Objective c UISplitViewController和模态UIViewController的问题
我的iPhone/iPad应用程序有一个非常奇怪的UI故障。因为我想找到它的原因,所以我创建了一个新项目,使用尽可能少的代码。下面是重要的代码 基本上,我有一个Objective c UISplitViewController和模态UIViewController的问题,objective-c,ipad,uiviewcontroller,Objective C,Ipad,Uiviewcontroller,我的iPhone/iPad应用程序有一个非常奇怪的UI故障。因为我想找到它的原因,所以我创建了一个新项目,使用尽可能少的代码。下面是重要的代码 基本上,我有一个UISplitViewController包含两个子类UIViewController。当点击一个按钮时,第一个按钮以模态方式显示,并显示为UIModalPresentationFormSheetaUIViewController名为Modal的子类。在那里,当点击一个按钮时,会显示另一个名为Text的UIViewController子类
UISplitViewController
包含两个子类UIViewController
。当点击一个按钮时,第一个按钮以模态方式显示,并显示为UIModalPresentationFormSheet
aUIViewController
名为Modal
的子类。在那里,当点击一个按钮时,会显示另一个名为Text
的UIViewController
子类,这次显示为UIModalPresentationFullScreen
。在Text
中,有一个UITextView
。当它被点击时,一切正常,但当iPad旋转时,我得到以下信息:
白色部分是文本
视图控制器,背景中的红色部分是视图控制器两个
有人知道为什么会这样吗?我能做些什么来修复它
以下是项目:
以下是相关的源代码:
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewControllerOne *one = [[ViewControllerOne alloc] init];
ViewControllerTwo *two = [[ViewControllerTwo alloc] init];
UISplitViewController *split = [[UISplitViewController alloc] init];
split.viewControllers = [NSArray arrayWithObjects:one, two, nil];
self.window.rootViewController = split;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
// ViewControllerOne.m
#import "Modal.h"
@implementation ViewControllerOne
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(30, 30, 44, 44);
[button addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)buttonTapped
{
Modal *modalOne = [[Modal alloc] init];
modalOne.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:modalOne animated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Modal.m
#import "Text.h"
@implementation Modal
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOne.frame = CGRectMake(30, 30, 44, 44);
buttonOne.tag = 1;
[buttonOne addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonTwo.frame = CGRectMake(30, 100, 44, 44);
buttonTwo.tag = 2;
[buttonTwo addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonOne];
[self.view addSubview:buttonTwo];
}
- (void)buttonTapped:(UIButton *)button
{
if (button.tag == 1)
{
Text *text = [[Text alloc] init];
text.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:text animated:YES];
}
else
{
[self dismissModalViewControllerAnimated:YES];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Text.m
@implementation Text
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:textView];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
您可能需要从UISplitViewController而不是其子视图中显示模式视图
UISplitViewController *splitViewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController];
[splitViewController presentModalViewController:modal animated:YES];
你能为展示这种行为的示例项目提供一个下载链接吗?@SebastianCelis现在上传了它,请看问题。你的存档无法生成。它引用了您项目之外的文件。@SebastianCelis希望它现在能工作。忘记“将项目复制到目标组的文件夹”。。。