【问题标题】:presentModalViewController fullscreenmode issuepresentModalViewController 全屏模式问题
【发布时间】:2011-09-30 07:33:24
【问题描述】:

我正在尝试在我的应用中展示这个 modalViewController,它需要全屏显示。

这就是我调用 ModalViewController 的方式。

myViewController = [[MyViewController alloc] init];
//self.myViewController.SomeView = [[UIView alloc] init];
//self.myViewController.SomeView.frame = self.ThisView.frame;
//self.myViewController.backButtonEnabled = NO;
//self.myViewController.dismissDelegate = self;
//[self.myViewController doLoadShizzle]; //do this to load view and stuffs as well
//all commented to try to make the edit construction work

UINavigationController *navController = [[UINavigationController alloc]
                                         initWithRootViewController:self.myViewController];

navController.modalPresentationStyle = UIModalPresentationFullScreen;

[self presentModalViewController:navController animated:YES];

[self.myViewController release];
[navController release];

navController.modalPresentationStyle 适用于除全屏模式之外的所有内容。 我已经在 ViewDidLoad 中记录了模态视图的 self.view,它具有正确的尺寸(包括对状态栏的调整)

NSLog (modalviewcontroller.view) =>

NSLog (modalviewcontroller.SomeView =>

我在这里做错了(显然),但我似乎无法弄清楚它是什么。 我一直在寻找解决方法,但到目前为止,没有一个选项是答案。 如果有人知道这里的问题是什么,我非常想知道。

提前致谢。

//---编辑---//

好的,现在我构建了这个原型,并且我确认这段代码可以按照我的意愿工作。然而,我似乎无法在我更大的架构中实现同样的东西。

--------.h (mainVC)

#import <UIKit/UIKit.h>
#import "ModalFullScreenShizzle.h"

@interface ModalViewControllerFullScreenTry2ViewController : UIViewController    <ModalViewDelegate>
{
    ModalFullScreenShizzle *fullscreenShizzle;
}

@property (nonatomic,retain) ModalFullScreenShizzle *fullscreenShizzle;

-(void)gotoFullscreenModal;

@end

-----------.m (mainVC)

@implementation ModalViewControllerFullScreenTry2ViewController

@synthesize fullscreenShizzle;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor yellowColor];

    UIButton *fullscreenActivate = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    fullscreenActivate.backgroundColor = [UIColor greenColor];
    [fullscreenActivate addTarget:self action:@selector(gotoFullscreenModal) forControlEvents:UIControlEventTouchUpInside];
    [fullscreenActivate setTitle:@"Full Screen ACTIVATE!!!!!!1111one" forState:UIControlStateNormal];
    [self.view addSubview:fullscreenActivate];
}

-(void)gotoFullscreenModal
{
    self.fullscreenShizzle = [[ModalFullScreenShizzle alloc] init];
    self.fullscreenShizzle.theScreen.frame = self.view.frame;
//    self.fullscreenShizzle.dismissDelegate = self;

    UINavigationController *navController = [[UINavigationController alloc]
                                         initWithRootViewController:self.fullscreenShizzle];

    navController.modalPresentationStyle = UIModalPresentationFullScreen;

    [self presentModalViewController:navController animated:YES];

//    [self.fullscreenShizzle release];
//    [navController release];

}

-(void)didDismissModalView
{
    [self dismissModalViewControllerAnimated:YES];
}

-----------.h (modalVC)

#import <UIKit/UIKit.h>

@protocol ModalViewDelegate <NSObject>

- (void)didDismissModalView;

@end

@interface ModalFullScreenShizzle : UIViewController
{
    UIView *theScreen;
    id<ModalViewDelegate> dismissDelegate;
}

@property (nonatomic, retain) UIView *theScreen;
@property (nonatomic, assign) id<ModalViewDelegate> dismissDelegate;

@end

-------------.m (modalVC)

#import "ModalFullScreenShizzle.h"

@implementation ModalFullScreenShizzle

@synthesize theScreen;

- (void)loadView
{
    [super loadView];
    self.view.frame = theScreen.frame;
    self.view.backgroundColor = [UIColor blueColor];
}

//---编辑 2---//

我已经完成了上面的代码并尝试将它添加到主 mainVC 窗口。 它可以工作,但不符合自动调整大小。然而,即使自动调整大小工作正常,这(有点)是一个肮脏的修复,而不是我想使用的正确解决方案。这也不是窗口显示自己的顺序。 与此同时,我正在使用其他(工作)演示风格之一。 但我仍然想知道解决方案..

..如果有人知道那是。

【问题讨论】:

    标签: objective-c modalviewcontroller uimodalpresentationstyle


    【解决方案1】:

    也许问题是:

     self.myViewController.SomeView = [[UIView alloc] init];
     self.myViewController.SomeView.frame = self.ThisView.frame;
    

    尝试在 MyViewController 的 viewDidLoad 或 loadView 中执行此操作。

    --

    编辑

    查看您的编辑代码后,我仍然认为问题在于您在尚未加载视图时设置了框架。

    【讨论】:

    • 我现在尝试在 loadview 和 viewdidload 中分配我的 modalviewcontroller 的视图。我已将父框架传递给 modalview 并使 modalviewcontroller.SomeView = parentFrame。它仍然无法正常工作。以下是我所看到的:我只在横向模式下工作并且自动旋转已打开(应该如此)。仍然当我按下弹出 modalviewcontroller 的按钮时,它会侧向旋转父视图(在他自己的框架内),然后该视图变为黑色并且不显示任何内容。
    • 不要使用父框架!改用边界(包括旋转校正)并实现 shouldAutorotateToInterfaceOrientaiton 方法。在没有导航控制器的情况下呈现视图控制器是否有效?
    • 自动旋转不是这里的问题。它已在 modalviewcontroller 的超类中处理(它适用于其他类,与我在这里实现它的方式相同)“在没有导航控制器的情况下呈现视图控制器是否有效?” -> 你这是什么意思?当我将其显示为普通 UIViewController 时,我的视图是否正确显示?在这种情况下是的,但它会获得一个自定义导航栏,用于所有正常的其他视图。其次它不会填满整个屏幕,但它的一部分(它需要覆盖底部和导航栏)它只填充调用模态的类分配的屏幕
    • 我把所有的frame设置都注释掉了,只在modalVC的loadview里面设置了(也试过在viewdid出现同样的效果)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    相关资源
    最近更新 更多