所以我正在测试这个,所以我可以在我的大项目中使用它。 我有一个名为TabBar的tabbarcontroller 这个TabBar有2个标签,每个标签都有一个navigationcontroller。带有按钮的ViewController(OkButtonViewController)当您单击此按钮时,您将转到带有标签(LabelViewController)的viewcontroller。 OkButton View Controller始终处于纵向状态,labelViewController可以切换方向。这只适用于一种情况,它会出错。当你在LabelViewController中,以横向为导向,并且切换选项卡时,OkButtonViewController也处于横向状态,并保持在横向状态。我如何强制viewcontroll回到肖像?
这是我的代码。
我可能需要在TabBar或RotatingTabBarAppDelegate中添加一些内容。我只是不知道是什么。
TabBar.m
#import "TabBar.h"
@implementation TabBar
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
@end
RotatingTabBarAppDelegate.h
#import <Foundation/Foundation.h>
#import "TabBar.h"
@class RotatingTabBarAppViewController;
@interface RotatingTabBarAppDelegate : NSObject<UIApplicationDelegate>
{
IBOutlet UIWindow *window;
}
@property (nonatomic, strong) UIWindow *window;
@end
RotatingTabBarAppDelegate.m
@implementation RotatingTabBarAppDelegate
@synthesize window;
-(void) applicationDidFinishLaunching:(UIApplication *)application
{
UIViewController *tab1 = [[UIViewController alloc] init];
tab1.tabBarItem =[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:0];
UIViewController *tab2 = [[UIViewController alloc] init];
tab2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1];
TabBar *tbc = [[TabBar alloc] init];
[tbc setViewControllers:[NSArray arrayWithObjects:tab1, tab2, nil]];
[window addSubview:tbc.view];
[window makeKeyAndVisible];
}
@end
OkButtonViewController.h
#import <UIKit/UIKit.h>
@interface OkButtonViewContoller : UIViewController
- (IBAction)ok;
@end
OkButtonViewController.m
#import "OkButtonViewController.h"
#import "LabelViewController.h"
#define kDetailSegue @"Detail"
@implementation OkButtonViewContoller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)ok
{
[self performSegueWithIdentifier:kDetailSegue sender:@"test"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:kDetailSegue]) {
((LabelViewController *)segue.destinationViewController).testTekst = sender;
}
}
@end
LabelViewController.h
#import <UIKit/UIKit.h>
@interface LabelViewController : UIViewController
@property (nonatomic, strong) NSString *testTekst;
@property (nonatomic, strong) IBOutlet UILabel *testLabel;
@end
LabelViewController.h
#import "LabelViewController.h"
@implementation LabelViewController
@synthesize testTekst;
@synthesize testLabel;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.testLabel.text = testTekst;
}
@end
抱歉英语不好。
答案 0 :(得分:2)
您无法强制转换视图,Apple可能拒绝您的应用,您需要找到另一种设计方式。