[英]Moving UIImageView frame programmatically
我有UIView,在其顶部我有一个UIImageView,在底部UICollectionView中。 我的观点是,当用户向上滑动手指时,UIImageView框架应轻轻移出(消失),而当用户向下滑动手指时,UIImageView框架应再次出现(带有移动动画)。
实际上,它一直有效,直到我将图像设置为UIImageView。 旧代码(如下所示)可以正常工作:
-(void)handleSwipeDown:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received.");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
self.myCollectionView.frame = CGRectMake(0, 152, 320, 480);
[UIView commitAnimations];
}
接着:
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received.");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
self.myCollectionView.frame=CGRectMake(0, 0, 320, 480);
[UIView commitAnimations];
}
我设置图像后:
UIImage *firstImage = [UIImage imageNamed:@"ipd1.jpg"];
self.imageSlideshow.image = firstImage;
上面的代码停止工作。 UIImage框架保持在同一位置。 我该如何移动? 任何建议,将不胜感激,谢谢!
您应该停止使用beginAnimations:context:
和commitAnimations
块。 根据Apple的文档:
不鼓励在iOS 4.0及更高版本中使用此方法。 您应该改用基于块的动画方法来指定动画。
使用此代替:
[UIView animateWithDuration:0.5 animations:^{
self.myCollectionView.frame = CGRectMake(0, 152, 320, 480);
}];
只需将整个swipeDown方法替换为上面的方法即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.