3

I have a UIScrollView to display a longer listing of textviews, fields and images. In the viewDidAppear I set the contentSize appropriately and I also add this code to didRotateFromInterfaceOrientation so that the UIScrollView contentSize resizes based on the orientation.

Problem is that when the view first appears the UIScrollView doesn't respond (I can't scroll) but after rotating the device the code in didRotateFromInterfaceOrientation is called and everything works perfectly. (If I start the app in landscape orientation I can only scroll a little bit to see what is normally displayed in portrait mode and not the extended content - ignores the scrollView I've defined)

The code is the same in viewDidAppear and didRotateFromInterfaceOrientation so why does the scrollView only respond after rotation? Any help appreciated.

The output from the NSLog messages in both methods is the same.

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;


- (void) viewDidAppear:(BOOL)animated{
   //If not an iPad set the scrollview to allow scrolling of view
   if (!([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)) {
      self.scrollView.contentSize= CGSizeMake(self.view.frame.size.width,1000);
      [self.scrollView setUserInteractionEnabled:YES];
   }
   if(self.scrollView.userInteractionEnabled){
    NSLog(@"DEBUG scrollview height : %f",self.scrollView.contentSize.height);
    NSLog(@"DEBUG scrollview width : %f",self.scrollView.contentSize.width);    
   }
}

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
//If not an iPad set the scrollview

    if (!([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)) {
        self.scrollView.contentSize= CGSizeMake(self.view.frame.size.width,1000);
    }
    if(self.scrollView.userInteractionEnabled){
       NSLog(@"DEBUG scrollview height : %f",self.scrollView.contentSize.height);
       NSLog(@"DEBUG scrollview width : %f",self.scrollView.contentSize.width);
    }
}
4

2 に答える 2