我制作了UIScrollView
,其宽度随触摸而变化。当前视图控制器切换到下一个时,我想保存UIScrollView的宽度。再次显示视图控制器时,应恢复UIScrollView
的宽度。
//TouZiViewController is the current view controller
@implementation TouZiViewController
...
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"toTouZi2"])
{ //TouZi2ViewController is the destination view controller
TouZi2ViewController *viewController2=[segue destinationViewController];
//huatiaoRect is CGRect,fullHuaTiao is the outlet of UIScrollView
viewController2.huatiaoRect=self.fullHuaTiao.frame;
}
}
@end
@implementation TouZi2ViewController
...
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"toTouZi"])
{
TouZiViewController *viewController=[segue destinationViewController];
[viewController loadView];
viewController.fullHuaTiao.frame=self.huatiaoRect;
}
}
@end
问题在于,当我从第二个视图控制器返回时,UIScrollView
的位置比以前高很多。为什么是这样?
的更新
现在我发现问题是因为自动化。我在故事板中更改自动调整,然后它运行良好。
答案 0 :(得分:1)
我认为问题可能是在设置帧之前调用loadview方法。如果没有记录Frame值并找到值更改的位置
更改为此并尝试
viewController.fullHuaTiao.frame=self.huatiaoRect;
[viewController loadView];