翻转动画的变革形象UIImageView的一半 [英] Change UIImageView image half way of a flip animation
问题描述
我怎样才能改变一个翻转动画的半路上一个UIImageView的形象。
我的code似乎翻转和UIImageView的成功改变形象,但它是在瞬间发生变化。我想实现的是,一旦180翻转了90度翻转,只改变图像。这里是我的code:
How can I change the image of a UIImageView on half way of a Flip animation. My code does seem to flip the UIImageView and successfully change the image but it is changing in an instant. What I want to achieve is to only change the image once the 180 flip reaches the 90 degree flip. Here is my code:
在视图中创建的UIImageView:
Create UIImageView on view:
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];
动画的UIImageView上点击:
Animate UIImageView on Tap:
[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的龙头姿态此动画。
Also, I am doing this animation on a tap gesture on the specific UIImageView.
推荐答案
您可以使用的UIView
类方法 +(无效)transitionWithView:时间:选项:动画:完成:
这个动画很容易
You can use UIView
class method + (void)transitionWithView:duration:options:animations:completion:
for this animation easily.
使用code这样的动画:
Use code like this for your 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
}];
您可以通过更换设置翻转方向 UIViewAnimationOptionTransitionFlipFromRight
与任何下列选项:
You can set direction of flip by replacing UIViewAnimationOptionTransitionFlipFromRight
with any of the following options:
UIViewAnimationOptionTransitionFlipFromLeft
UIViewAnimationOptionTransitionFlipFromRight
UIViewAnimationOptionTransitionFlipFromTop
UIViewAnimationOptionTransitionFlipFromBottom
这篇关于翻转动画的变革形象UIImageView的一半的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!