1

我有一个 UIScrollview 加载良好,显示良好,一切都很好。然后我推送另一个视图控制器,称之为 VC2,它也可以正常工作。从 VC2 我弹出回到 UIScrollview,这是奇怪的行为......当 UIScrollview 回来时,从顶部开始的第一个(我猜)300 像素被切断。如果我拉下页面,我仍然可以看到内容,但显然这对我不起作用。有人有什么想法吗?

这是代码:

这是创建 ScrollView:

-(IBAction)startNewSearch:(id)sender
{
NewSearch *VCscrollView = [[NewSearch alloc] init];
[[self navigationController] pushViewController:VCscrollView animated:YES];
}

滚动视图

- (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];
}
4

1 回答 1

1

正确答案的功劳归安德烈·索洛维耶夫所有,但不幸的是他没有发帖让我给他功劳。添加代码:

-(void)viewWillAppear:(BOOL)animated
{
scrollView.frame = CGRectMake(0, 0, 320, 890);
}

fixed the problem as described. The root of the problem ended up being a little more complex and outside of the scope of my question.

于 2012-11-20T15:40:52.050 回答