Ios 为UIAlertView创建抖动动画
我正在尝试制作一个Ios 为UIAlertView创建抖动动画,ios,objective-c,animation,uialertview,Ios,Objective C,Animation,Uialertview,我正在尝试制作一个UIAlertViewshake。我已经使alertView停留在按钮单击上,但抖动动画不起作用。以下是我所拥有的: - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { self.direction = 1; self.shakes = 0; [se
UIAlertView
shake。我已经使alertView
停留在按钮单击上,但抖动动画不起作用。以下是我所拥有的:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
self.direction = 1;
self.shakes = 0;
[self shake:aUIView];
}
}
-(void)shake:(UIAlertView *)theOneYouWannaShake
{
[UIView animateWithDuration:0.03 animations:^ {
theOneYouWannaShake.transform = CGAffineTransformMakeTranslation(5 * self.direction, 0);
}
completion:^(BOOL finished) {
if(self.shakes >= 10) {
theOneYouWannaShake.transform = CGAffineTransformIdentity;
return;
}
self.shakes++;
self.direction = self.direction * -1;
[self shake:theOneYouWannaShake];
}];
}
我试着把一个
NSLog
放到-(void)shake…
中,得到了一个输出。因此,我的代码一定有问题,为什么alertView
没有抖动。您可以在iOS中使用UIKit Dynamics获得动画效果。下面是一个使用UIKit Dynamics进行UIAlertView
抖动动画的示例。有关更多信息,您也可以参考swift中的这一部分。您可以使用iOS中的UIKit Dynamics来获得动画效果。下面是一个使用UIKit Dynamics进行UIAlertView
抖动动画的示例。有关更多信息,您也可以参考swift中的这一部分。您可以使用iOS中的UIKit Dynamics来获得动画效果。下面是一个使用UIKit Dynamics进行UIAlertView
抖动动画的示例。有关更多信息,您也可以参考swift中的这一部分。您可以使用iOS中的UIKit Dynamics来获得动画效果。下面是一个使用UIKit Dynamics进行UIAlertView
抖动动画的示例。更多信息,请参阅swift中的这篇文章。我创造了一种错觉,使alertview看起来像是在摇晃。前提是您必须设置alertview(包括黑色背景屏幕)应震动的范围的参数
因为你不能改变UIAlertView的框架,所以继续使用CGTransformations
UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message:"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Done", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
UIView *dillusionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[dillusionView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dillusionView];
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x - 10, dialog.frame.origin.y);
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x + 10, dialog.frame.origin.y);
}];
} completion:nil];
我建议改为使用自定义创建的UIAlertView,而且几乎没有可用的开源库 我创造了一种错觉,使alertview看起来像是在摇晃。前提是您必须设置alertview(包括黑色背景屏幕)应震动的范围的参数 因为你不能改变UIAlertView的框架,所以继续使用CGTransformations
UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message:"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Done", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
UIView *dillusionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[dillusionView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dillusionView];
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x - 10, dialog.frame.origin.y);
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x + 10, dialog.frame.origin.y);
}];
} completion:nil];
我建议改为使用自定义创建的UIAlertView,而且几乎没有可用的开源库 我创造了一种错觉,使alertview看起来像是在摇晃。前提是您必须设置alertview(包括黑色背景屏幕)应震动的范围的参数 因为你不能改变UIAlertView的框架,所以继续使用CGTransformations
UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message:"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Done", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
UIView *dillusionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[dillusionView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dillusionView];
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x - 10, dialog.frame.origin.y);
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x + 10, dialog.frame.origin.y);
}];
} completion:nil];
我建议改为使用自定义创建的UIAlertView,而且几乎没有可用的开源库 我创造了一种错觉,使alertview看起来像是在摇晃。前提是您必须设置alertview(包括黑色背景屏幕)应震动的范围的参数 因为你不能改变UIAlertView的框架,所以继续使用CGTransformations
UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message:"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Done", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
UIView *dillusionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[dillusionView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dillusionView];
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x - 10, dialog.frame.origin.y);
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x + 10, dialog.frame.origin.y);
}];
} completion:nil];
我建议改为使用自定义创建的UIAlertView,而且几乎没有可用的开源库 同样,您必须将UIView/AlertView子类化或使用此library@user3693546我试过了,但没用。你是引用整个屏幕来抖动还是只引用AlertView?只引用
AlertView
@Jessica请看答案Jessy。同样,你必须对UIView/AlertView进行子类化或使用此选项library@user3693546我试过了,但是它不起作用。您是引用整个屏幕来抖动还是仅引用AlertView?仅引用AlertView
@Jessica请参见回答Jessiy。同样,您必须对UIView/AlertView进行子类化或使用此选项library@user3693546我试过了,但没用你是指整个屏幕摇晃还是仅仅是AlertView?仅仅是alertView
@Jessica请参见答案Jessy。同样,您必须将UIView/alertView子类化或使用此选项library@user3693546我试过了,但没用你是指整个屏幕摇晃还是仅仅是AlertView?只是AlertView
@Jessica请看答案Jessy。你是说我应该从头开始(从UIView)吗你是说我应该从头开始(从UIView)吗?你是说我应该从头开始(从UIView)吗?你是说我应该从头开始(从UIView)吗?