UIScrollview content size when orientation changes

前端 未结 2 438
醉酒成梦
醉酒成梦 2021-01-19 05:01

I have a scrollview with pagination. In viewDidLoad i check if the current orientation is landscape then i set its contentsize\'s height 440

 if (UIDeviceOri         


        
2条回答
  •  不思量自难忘°
    2021-01-19 05:26

    1. Don't use UIDeviceOrientation. Use UIInterfaceOrientation instead. DeviceOrientation has two extra options you don't need here. (UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown)

    2. Return Yes from shouldAutorotateToInterfaceOrientation

    3. Now willRotateToInterfaceOrientation: duration: will be called every time you rotate your device.

    4. Implement this method like this.

      -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
      {
      CGRect frame;
      int pageNumber = 2;
      int statusBarHeight = 20;
      
      if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
          frame = CGRectMake(0, 0, 480, 320 - statusBarHeight);
      } else {
          frame = CGRectMake(0, 0, 320, 480 - statusBarHeight);
      }
      
      scrollView.frame = frame;
      scrollView.contentSize = CGSizeMake(frame.size.width * 2, frame.size.height);
      } 
      

      Let,

      pageNumber = 2

      statusBarHeight = 20

提交回复
热议问题