简体   繁体   中英

UIScrollView resizing

I'm very new in iOS development. Sorry for my English. I'm trying to make simple form, multi-view, universal app.But I have a serious problem with my scrollView. I'm adding my pages (4 count) via addSubview: method and everything is run good, but when I rotate device everything becomes to a completely mess. I think that I don't resize my ScrollView correctly. What is the best approach in my case? I'm using Xcode5 . This is the piece of code where I add my subViews.

-(void)scrollViewResize{
    scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    [scrollView setContentOffset:CGPointMake(0, 0)animated:NO];
    [scrollView setContentSize:currentView1.frame.size];
    [scrollView addSubview:currentView1];
    [scrollView setScrollEnabled:YES];
}

-(void)viewDidLayoutSubviews{
  [super viewDidLayoutSubviews];
  [self.scrollView layoutIfNeeded];
  self.scrollView.contentSize = self.testView.frame.size;
 }

http://imageshack.us/photo/my-images/585/n281.png/ - when I Run in Landscape mode

http://imageshack.us/photo/my-images/20/21ma.png/ - when I Run in Landscape mode and rotate to portrait

If I Run my app in portrait and then I rotate in Landscape it works fine for 1st subView.

As you stated that you're new to iOS programming then you should read some tutorials about Autoresize mask . Autoresize mask is good solution in your case.

http://www.techpaa.com/2012/05/understanding-uiview-autoresizing.html http://mobile.tutsplus.com/tutorials/iphone/working-with-the-iphone-5-display/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM