更改UIImageView图像翻转animation的一半
如何在翻转animation的一半更改UIImageView的图像。 我的代码似乎翻转了UIImageView,并成功地改变了图像,但它瞬间改变。 我想达到的目的只是在180度翻盖达到90度翻盖后才改变图像。 这是我的代码:
在视图上创buildUIImageView:
UIImage *image = [UIImage imageNamed:@"fb1.jpg"]; imageView = [[UIImageView alloc] initWithImage:image]; vw = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)]; vw.layer.cornerRadius = vw.frame.size.width / 2; imageView.frame = CGRectMake(20, 20, 80, 80); imageView.layer.cornerRadius = imageView.frame.size.width / 2; imageView.layer.masksToBounds = YES; imageView.layer.borderColor = [[UIColor blackColor] CGColor]; imageView.layer.borderWidth = 1.0; [self.view addSubview: imageView]; //[self.view addSubview:vw]; [imageView setUserInteractionEnabled:YES]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(taptap:)]; [imageView addGestureRecognizer:tap];
在Tap上Animate UIImageView:
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { imageView.transform = CGAffineTransformMakeScale(-1, 1); [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^(void) { imageView.image = [UIImage imageNamed:@"fb2.jpg"]; } completion:^(BOOL finished) { }]; } completion:^(BOOL finished) { }];
另外,我正在做特定的UIImageView上的轻拍手势这个animation。
您可以使用UIView
类方法+ (void)transitionWithView:duration:options:animations:completion:
为这个animation很容易。
为你的animation使用这样的代码:
[UIView transitionWithView:imageView duration:0.4 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ // Set the new image // Since its done in animation block, the change will be animated imageView.image = newImage; } completion:^(BOOL finished) { // Do whatever when the animation is finished }];
您可以通过使用以下任一选项replaceUIViewAnimationOptionTransitionFlipFromRight
来设置翻转的方向:
UIViewAnimationOptionTransitionFlipFromLeft UIViewAnimationOptionTransitionFlipFromRight UIViewAnimationOptionTransitionFlipFromTop UIViewAnimationOptionTransitionFlipFromBottom
尝试两个步骤的animation,如果你不喜欢这个,你可以查看连接选项的文档。
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^(void) { //do your half rotation here imageView.transform = CGAffineTransformMakeScale(0, 1); } completion:^(BOOL finished) { if(finished){ imageView.image = [UIImage imageNamed:@"fb2.jpg"]; [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^(void) { //do your second half rotation here imageView.transform = CGAffineTransformMakeScale(-1, 1); } completion:^(BOOL finished) { }]; } }];
- Swift:影响button点击的UITextfield? 由于animation无法input文字?
- 在X方向旋转两个UIImageView
- launchscreen.storyboard和main.storyboard有什么不同?
- 在Swift中animation自定义UIView属性
- drawRect圆和animation大小/颜色
- 使用贝塞尔path作为剪贴蒙版
- swift UIView animateWithDuration重复和自动反向
- 当有很多使用阴影的UILabels运行的UIViewanimation时,设备会冻结,然后按Homebutton
- 认定animation类似于在iOS 7中打开应用程序:viewcontroller框架不能resize