UIScrollView无法正确还原 [英] UIScrollView does not restore properly
问题描述
我有一个Scrollview,它的属性在viewDidAppear中设置. 现在,当我第一次进入Scrollview时,没有任何问题.但是我有分配给UINavigationController的按钮.因此,当我按其中一个UINavigationController打开时,当我关闭导航控制器时,ScrollView无法正确还原.它基本上将屏幕的中心与先前按下的按钮位置对齐.因此,如果我尝试向上滚动,则不会.
I have a Scrollview, it's properties are set in viewDidAppear. Now when I get to the Scrollview first time there isn't any problem. However I have buttons that are assigned to UINavigationController. So when I press into one of them UINavigationController opens up, when I close the navigation controller, ScrollView does not restore properly. It basically aligns the centre of the screen as previously pressed button location. So if I try to scroll up it does not.
我尝试在viewDidAppear中使用它:
I have tried using this in my viewDidAppear:
scrollView.center = CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y);
哪个工作不太好.我该如何解决?我正在使用iOS6.1
Which did not quite work. How can I solve this? I am using iOS6.1
推荐答案
实际上,我在这里找到了答案:
Actually I found the answer here:
我使用的确切代码是:
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
//save the current offset
previousPoint = scrollView.contentOffset;
//set current view to the beginning point
self.scrollView.contentOffset = CGPointZero;
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
//retrieve the previous offset
self.scrollView.contentOffset = previousPoint;
}
previousPoint
只是在实现中声明的CGPoint变量.
previousPoint
is nothing but a CGPoint variable declared on the implementation.
这篇关于UIScrollView无法正确还原的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!