目前ModalViewController全屏模式问题
我试图在我的应用程序中呈现这个 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 中记录了 modalview 的 self.view ,它具有正确的尺寸(包括对状态栏的调整)
NSLog (modalviewcontroller.view) => < UI视图:0x7d173a0;帧=(20 0;748 1024);自动调整大小=W+H;层=>
NSLog (modalviewcontroller.SomeView => < UIView: 0x7d154a0; frame = (0 0; 1024 660); layer = >
我在这里做错了什么(显然),但我似乎不知道它是什么。 我一直在寻找解决方法,但到目前为止,没有一个选项是答案。 如果有人知道这里的问题是什么,我非常想知道。
提前致谢。
//---编辑---//
好的,现在我构建了这个原型,并且我确认这段代码可以按照我想要的方式工作。然而,我似乎无法在更大的架构中实现同样的事情。
--------.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---//
我已经完成了上面的代码并尝试将其添加到主 mainVC 窗口。 它可以工作,但不符合自动调整大小。然而,即使自动调整大小工作正常,这也是(有点)肮脏的修复,而不是我想使用的正确解决方案。而且它也不是窗口显示本身的顺序。 与此同时,我正在使用其他(工作)演示风格之一。 但我仍然想知道解决方案
......如果有人知道的话。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许问题是:
尝试在 MyViewController 的 viewDidLoad 或 loadView 中执行此操作。
--
编辑
查看您的编辑代码后,我仍然认为问题是您在视图尚未加载时设置框架。
Maybe the problem is :
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.