ECSlidingViewController

ECSlidingViewController

真的被困了好几个星期了。我正在使用ECSlidingViewController,并且我希望一个视图能够旋转到横向和纵向,因为它是横向照片,并且需要利用可用空间,而我不希望其余的应用程序旋转,只待在风景中。

我确定自动旋转方法不会被调用,因为它使用此技术切换到视图...

- (void)setTopViewController:(UIViewController *)theTopViewController
{
  CGRect topViewFrame = _topViewController ? _topViewController.view.frame : self.view.bounds;

  [self removeTopViewSnapshot];
  [_topViewController.view removeFromSuperview];
  [_topViewController willMoveToParentViewController:_topViewController];
  [_topViewController removeFromParentViewController];

  _topViewController = theTopViewController;

  [self addChildViewController:self.topViewController];
  [self.topViewController didMoveToParentViewController:self];

  [_topViewController.view setAutoresizingMask:self.autoResizeToFillScreen];
  [_topViewController.view setFrame:topViewFrame];
  _topViewController.view.layer.shadowOffset = CGSizeZero;
  _topViewController.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;

    [self.view addSubview:_topViewController.view];
}


在我的初始viewcontroller上...

self.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"Home"];


因此,它只是堆叠在顶部,而不是切换到该视图。因此,它总是在听初始视图控制器的旋转方法...

非常感谢您的帮助,正如我所说的,我已经被困了好几天了。

最佳答案

经过几个小时的努力,终于我可以完成这项工作了。

首先,您需要创建ECSLidingViewController的子视图,并放置以下代码:

-(NSUInteger)supportedInterfaceOrientations{
     return [self.topViewController supportedInterfaceOrientations];
 }

-(BOOL)shouldAutorotate{
     return self.topViewController.shouldAutorotate;
 }

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
     return [self.topViewController preferredInterfaceOrientationForPresentation];
 }


您还需要创建一个UINavigationController类别并覆盖此代码

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate{
     return [[self.viewControllers lastObject] shouldAutorotate];
 }

-(NSUInteger)supportedInterfaceOrientations{
     return [[self.viewControllers lastObject] supportedInterfaceOrientations];
 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
     return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
 }

@end


希望这项工作对您有帮助。

10-08 07:47