问题描述
我有一个UIImageView作为我的tabbarcontroller视图之一,我添加了一个UISwipeGestureRecognizer(右和左)浏览一系列的照片在NSArray。
I have a UIImageView as one of my tabbarcontroller views, and I've added a UISwipeGestureRecognizer (right and left) to navigate through a series of photos in an NSArray.
但是,当滑动它从照片跳到照片没有平滑过渡。我没有什么奇怪,但即使一个幻灯片动画也没关系,就像一张照片滑入,另一个滑出另一侧。这是可能的UISwipeGestureRecgonizer和一个NSArray?
However, when swiping it jumps from photo to photo with no smooth transition. I'm not after anything fancy, but even a slide animation would be okay, like as one photo slides in, the other is sliding out the other side. Is this possible with the UISwipeGestureRecgonizer and an NSArray?
推荐答案
标准的解决方案是使用 UIScrollView
与 pagingEnabled = YES
和滚动视图内的多个图像视图。如果您只想使用一个 UIImageView
,请在识别滑动时向图片视图的图层添加一个过渡动画:
The standard solution is to use a UIScrollView
with pagingEnabled = YES
and multiple image views inside the scroll view. If you want to work with just one UIImageView
, add a transition animation to the image view's layer when you recognize a swipe:
CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromRight;
[myImageView.layer addAnimation:animation forKey:@"imageTransition"];
myImageView.image = newImage;
这篇关于要使用UISwipeGesture在NSArray中的图片之间平滑过渡或滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!