问题描述
我使用UIScrollView和其中的图像作为每页调页一个图像。旋转时出现问题
I am using UIScrollView and an image in it as paging one image per page. I have a problem while rotating the iPhone
旋转时iPhone然后scrollViewDidScroll(Scroll view delegate方法)正在调用。
When I rotate the iPhone then scrollViewDidScroll (Scroll view delegate method) is calling.Due to this, my paging is disturbed and the page number changes.
这是什么解决方案?
推荐答案
是一个很好的描述的问题,和一个整洁的修复。我有完全相同的问题,并以一个 scrollingLocked
标志,我在旋转开始前设置为YES(锁定),结束时NO(解锁)。也许比暂时改变contentSize稍微少一点hacky:
Raphaël's answer is an excellent description of the problem, and a neat fix. I had the exact same problem and ended up fixing with a scrollingLocked
flag that I set to YES (locked) before the rotation starts, and NO (unlocked) when it ends. Perhaps slightly less hacky than temporarily changing the contentSize:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
duration:(NSTimeInterval)duration
{
self.photoViewer.scrollingLocked = YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromOrientation
{
self.photoViewer.scrollingLocked = NO;
}
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
if (self.scrollingLocked)
{
return;
}
/* do normal scrollViewDidScroll: stuff */
}
这篇关于UIScrollView在iPhone / iPad上旋转时禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!