在我的应用程序中,我完成了从FirstViewController到FormViewController的转换。
[self presentModalViewController:formViewController animated:YES];
在FormViewController中,我想显示四个图像,每次用户单击一个图像时,我都会注意到字典中单击的图像的编号或名称,然后显示接下来的四个图像。因此,大约有8组4张图像。所以我的问题是,每四个图像应该显示在一个新的类中,或者我应该将所有的图像放在FormViewController中并使用.hidden?可以在改变图像时制作动画吗?不是所有视图的动画,只有图像。
发布于 2011-12-17 12:13:14
我会使用一个单独的xib和一个类。该类需要某种类型的数据模型来保存可用图像的列表、先前选择的图像和当前可见的图像。
当用户点击一张图片时,更新数据并显示新图片,就像这样淡出旧图片,淡入新图片。
/* ARC code */
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
/* destroy the transition view, set the image first */
UIImageView *transitionImageView = (UIImageView *)context;
self.pic.image = transitionImageView.image;
[transitionImageView removeFromSuperview];
transitionImageView = nil;
}
- (void)clickHandler:(id)sender {
/* temporary view for the animation */
UIImageView *transitionImageView = [[UIImageView alloc] initWithFrame:self.pic.frame];
transitionImageView.image = <# new UIImage #>;
transitionImageView.alpha = 0.0f;
[self.view addSubview:transitionImageView];
[UIView beginAnimations:@"UpdateImages" context:transitionImageView];
[UIView setAnimationDuration:2.0f];
transitionImageView.alpha = 1.0f;
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
根据您的四个图像进行调整。
如果你想要更花哨的动画,你可以有两组4个UIImageViews
,并使用它们来显示和动画的图像过渡。
发布于 2011-12-17 11:41:27
你可以在同一个类中显示图像,我个人认为这是你应该做的,因为它将更容易地管理你的代码,是的,你可以动态地改变图像。
https://stackoverflow.com/questions/8544398
复制