我是Objective-c和cocoa中的菜鸟,我想用翻转动画实现UIImageView的简单动画。但我很难做到这一点。以下是我的摘要:
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,33,33)];
UIImageView *img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:IMG1]];
UIImageView *img2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:IMG2]];
[containerView addSubview:img1];
[containerView addSubview:img2];
[self.view addSubview:containerView];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
感谢。
答案 0 :(得分:1)
您引用一个名为view
的对象,它永远不会被声明。我认为您需要将倒数第二行更改为
[containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
看看是否有帮助。