这就是我创建的一个继承 UINavigationController 的自定义类
自定义导航控制器.h
#import <UIKit/UIKit.h>
@interface CustomNavigationController : UINavigationController <UINavigationControllerDelegate>
@end
自定义导航控制器.m
#import "CustomNavigationController.h"
@interface CustomNavigationController ()
@end
@implementation CustomNavigationController
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
@end
父视图控制器
- (IBAction)btnSelected:(id)sender
{
FirstVC_New *firstVCOBJ = [[FirstVC_New alloc] initWithNibName:@"FirstVC_New" bundle:nil];
CustomNavigationController *navController = [[CustomNavigationController alloc]initWithRootViewController:firstVCOBJ];
navController.navigationBarHidden = YES;
[self.navigationController presentModalViewController:navController animated:NO];
}
在按钮上单击我正在展示新的 UIViewController。我为 FirstVC_New 编写的这些代码。
#pragma mark - Orientation methods.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (IBAction)btnNextSelected:(id)sender
{
SecondVC *secondVCOBJ = [[CouponDetailVC alloc]initWithNibName:@"CouponDetailVC" bundle:nil];
CustomNavigationController *navController = [[CustomNavigationController alloc]initWithRootViewController:couponDetailVCOBJ];
navController.navigationBarHidden = YES;
[self.navigationController presentModalViewController:navController animated:NO];
}
我在 SecondVC 中完成的这些代码。
#pragma mark - Orientation methods.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortraitUpsideDown;
}
现在从两种观点呈现都完美无缺。主要问题是我无法通过 SecondVC 进入主根视图
无论是这种方式
[self.parentViewController dismissModalViewControllerAnimated:NO];
或者这样
[self dismissModalViewControllerAnimated:NO];
建议我解决此问题的适当方法,如何使用 iOS 6 解决。