问题
I'm trying to present this modalViewController in my app and it needs to be fullscreen.
This is how I call up the 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];
The navController.modalPresentationStyle works for everything besides the full screen mode. I've logged the self.view of the modalview in the ViewDidLoad and it has the right dimensions (including the adjustments to the statusbar)
NSLog (modalviewcontroller.view) => < UIView: 0x7d173a0; frame = (20 0; 748 1024); autoresize = W+H; layer = >
NSLog (modalviewcontroller.SomeView => < UIView: 0x7d154a0; frame = (0 0; 1024 660); layer = >
Im doing something wrong here (obviously), but I can't seem to figure out what it is. I've been searching for stuff as workaround but none of the options have been the answer thus far. If anyone has a clue of what the issue is here, I would very much like to know.
Thanks in advance.
//---EDIT---//
Ok, now I build this prototype and I confirmed that this code is working as I want it to. Yet I can't seem to implement the very same thing in my larger architecture.
--------.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];
}
//---EDIT 2---//
I've done the code above this and tried to add it to main mainVC window. It works but it's not conforming to the autoresizing. Yet even if the autoresizing works properly this is (kinda) a dirty fix and not a proper solution that I'd like to use. Also it's not the the order of which windows show themselves. In the meantime I'm using one of the other (working) presentation styles. But I would still like to know the solution..
..if anyone knows that is.
回答1:
Maybe the problem is :
self.myViewController.SomeView = [[UIView alloc] init];
self.myViewController.SomeView.frame = self.ThisView.frame;
Try to do this inside the viewDidLoad or loadView of the MyViewController.
--
EDIT
After look your edit code, I am still think that the problem is that you are setting the Frame when the view is not loaded yet.
来源:https://stackoverflow.com/questions/7607271/presentmodalviewcontroller-fullscreenmode-issue