OGeek|极客世界-中国程序员成长平台

标题: ios - UIImage 在 UIImageView iOS 内滑动开/关 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:50
标题: ios - UIImage 在 UIImageView iOS 内滑动开/关

我在屏幕中央有一个 UIImageView(借助 Storyboard 的约束设置位置) 在代码的 viewDidLoad 方法中,我通过以下方式为该 imageView 设置图像:

self.imageView.image = [UIImage imageNamed"food"];

然后我想从 UIImageView 的左侧滑动旧图像并从 UIImageView 的右侧滑动新图像,我使用了以下代码(以下代码在识别滑动手势后触发,所以下面的代码在 swipeGestureRecognizer 的选择器方法中):

self.imageView.image = [UIImage imageNamed"picnic"];
CATransition *animation = [CATransition animation];
[animation setDuration:1];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.imageView layer] addAnimation:animation forKey:nil];

但是当我这样做时,新图像从屏幕的右边缘而不是 UIImageView 的右边缘出现在屏幕上,并且与一直推出到屏幕左边缘的旧图像相同而不是 UIImageView 的左边缘。 有什么办法可以解决吗? 任何帮助,将不胜感激。谢谢



Best Answer-推荐答案


您可以尝试将 ImageView 放入 View 中,该 View 也具有剪辑边界是的。我认为这应该会有所帮助。

关于ios - UIImage 在 UIImageView iOS 内滑动开/关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30719011/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4