旋转屏幕时如何调整 UIViewController 的框架大小?
我正在开发一个基于iPad 的程序。 我创建了新的模式 UIViewController 作为表单模式而不是全屏。 为了调整视图大小,我使用了以下代码。 ...
MyController* controller = [[MyController alloc] init];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController : controller animated: YES];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ( UIInterfaceOrientationIsPortrait(orientation) )
controller.view.superview.frame = CGRectMake(200, 100, 350, 600);
else
controller.view.superview.frame = CGRectMake(100, 200, 600, 350);
...
在 MyController 中,我将以下代码编码为 didRotateFromInterfaceOrientation。
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ( fromInterfaceOrientation == orientation )
return;
if ( UIInterfaceOrientationIsPortrait(orientation) )
{
self.view.frame = CGRectMake(0, 0, 350, 600);
self.view.superview.frame = CGRectMake(200, 100, 940, 628);
}
else
{
self.view.frame = CGRectMake(0, 0, 600, 350);
self.view.superview.frame = CGRectMake(100, 200, 600, 350);
}
}
但是当旋转屏幕时,视图不会调整大小,并且超级视图的宽度和高度具有意外的值。 请帮助我的问题。
I'm developing a program based iPad.
I created new modal UIViewController as formsheet mode not full screen.
And to resize the view, i used following codes.
...
MyController* controller = [[MyController alloc] init];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController : controller animated: YES];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ( UIInterfaceOrientationIsPortrait(orientation) )
controller.view.superview.frame = CGRectMake(200, 100, 350, 600);
else
controller.view.superview.frame = CGRectMake(100, 200, 600, 350);
...
in MyController, i taked following codeds as didRotateFromInterfaceOrientation.
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ( fromInterfaceOrientation == orientation )
return;
if ( UIInterfaceOrientationIsPortrait(orientation) )
{
self.view.frame = CGRectMake(0, 0, 350, 600);
self.view.superview.frame = CGRectMake(200, 100, 940, 628);
}
else
{
self.view.frame = CGRectMake(0, 0, 600, 350);
self.view.superview.frame = CGRectMake(100, 200, 600, 350);
}
}
but when rotate screen, the view don't be resized and width and height of superview has unexpect value.
please help my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试调试它,看看你实际上得到了什么方向。
你这样尝试过吗?
另请注意,有两个肖像方向。
try to debug it and see what orientation you get in fact.
Did you try like this?
Also note that there are two portairt orientations..