Sar*_*aya 1 uiscrollview viewdidappear ios
我有一个Scrollview,它的属性在viewDidAppear中设置.现在,当我第一次到Scrollview时,没有任何问题.但是我有分配给UINavigationController的按钮.因此当我按下其中一个UINavigationController打开时,当我关闭导航控制器时,ScrollView无法正常恢复.它基本上将屏幕中心对齐为先前按下的按钮位置.因此,如果我尝试向上滚动它不会.
我试过在我的viewDidAppear中使用它:
scrollView.center = CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y);
Run Code Online (Sandbox Code Playgroud)
哪个不太奏效.我怎么解决这个问题?我使用的是iOS6.1
其实我在这里找到了答案:
我使用的确切代码是:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
previousPoint 只不过是在实现上声明的CGPoint变量.
| 归档时间: |
|
| 查看次数: |
2340 次 |
| 最近记录: |