1
我有一個UIScrollview,加載正常,顯示正常,一切正常。然後我推另一個視圖控制器,稱之爲VC2,它也可以正常工作。從VC2開始我回到UIScrollview,這裏是一個奇怪的行爲......當UIScrollview回來時,第一個(我猜測)從頂部300像素被切斷。如果我把頁面拉下來,我仍然可以看到內容,但顯然這不適合我。任何人有任何想法?UIScrollview第二次顯示不正確
下面是代碼:
這是創建滾動型:
-(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.
}
IBAction爲從滾動型內調用VC2:
-(IBAction)previewSearch:(id)sender
{
VCcontactServer *VC2 = [[VCcontactServer alloc] init];
[[self navigationController] pushViewController:VC2 animated:YES];
}
嘗試檢查scrollView的autoresizingMask –
我試過使用scrollView.autoresizingMask = UIViewAutoresizingNone;並嘗試使用scrollView.autoresizingMask =(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);但結果相同。順便說一句,我在viewDidLoad中使用了這些命令。 – sangony
快速和不好的解決方案是爲viewView裏面的scrollView設置框架,但你必須弄清楚爲什麼你的scrollView調整大小。可能是你的scrollView的超級視圖沒有適當調整大小? 如果你發佈代碼,創建scrollView,將其添加到子視圖和你的loadView,viewDidLoad,並且如果你有viewDidAppear/Disappear,那麼更好, –