我有1000像素宽的大图像。我想以原始大小显示图像,我希望它在动画中自动从右向左滚动。例如,在iPhone 6中,它应首先显示375像素,然后应向左移动,直到照片的所有部分及时显示。我怎么能这样做?
答案 0 :(得分:1)
您可以使用setContentOffset函数以编程方式滚动UIScrollView。例如:
scrollView.setContentOffset(CGPoint(x: scrollView.frame.width - imageView.frame.width, y: 0), animated: true)
您还可以在UIView.animateWithDuration块中设置contentOffset属性,以获得更多受控动画。
答案 1 :(得分:1)
// You have to put the imageView inside a UIScrollView
// Set the duration you want for your animation
[UIView animateWithDuration:1.5f animations:^{
//Code for animation
[scrollView setContentOffset:CGPointMake(imageView.frame.size.width - scrollView.frame.size.width, scrollView.contentOffset.y) animated:NO];
} completion:^(BOOL finished) {
//Code after the animation is completed
}];