我有一个UIScrollview加载正常,显示正常,一切都很好。然后我推另一个视图控制器,称之为VC2,这也很好。从VC2我弹出回到UIScrollview,这是奇怪的行为...当UIScrollview回来时,第一个(我猜)从顶部300像素被切断。如果我把页面拉下来,我仍然可以看到内容,但显然这对我不起作用。有人有什么想法吗?
以下是代码:
这是创建ScrollView:
-(IBAction)startNewSearch:(id)sender
{
NewSearch *VCscrollView = [[NewSearch alloc] init];
[[self navigationController] pushViewController:VCscrollView animated:YES];
}
ScrollView
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView.contentSize = CGSizeMake(320, 890);
[scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
[scrollView flashScrollIndicators];
}
-(void)viewWillAppear:(BOOL)animated
{
scrollView.frame = CGRectMake(0, 0, 320, 890);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
从ScrollView中调用VC2的IBAction:
-(IBAction)previewSearch:(id)sender
{
VCcontactServer *VC2 = [[VCcontactServer alloc] init];
[[self navigationController] pushViewController:VC2 animated:YES];
}
答案 0 :(得分:1)
正确的答案归功于安德烈·索洛维耶夫,但不幸的是他没有发帖给我给他信用。添加代码:
-(void)viewWillAppear:(BOOL)animated
{
scrollView.frame = CGRectMake(0, 0, 320, 890);
}
按照描述修复了问题。问题的根源有点复杂,超出了我的问题范围。