本文介绍了pop over view的定位问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iPad中纵向切换到横向视图(& Vice Versa)时,我的弹出视图的位置会出现乱码。以下是我计算弹出视图框架的方法:

When I am switching between Portrait to Landscape view (&Vice Versa) in iPad, position of my popover view gets garbled. Here is how I am calculating frame of my popover view:

aRect = self.myElement.frame;
aRect.origin.x += aRect.size.width;

[aPopOver presentPopoverFromRect:aRect inView:self.myElement.superview permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

请告诉我这里有什么问题?

Please tell me whats wrong here?

推荐答案

好的,我注意到你的代码有些奇怪。

ok, i notice something weird about your code.

你要将广义的大小添加到原点的任何原因aRect的x位置?
aRect.origin.x + = aRect.size.width;

any reason you are adding the size of the wide to the origin of aRect's x position?aRect.origin.x += aRect.size.width;

我假设您希望这个位于右上角....

im assuming you want this to be the top right corner....

您可以取消注释.m文件中的代码,并将其设置为:

You can uncomment the code in your .m file and make it like so:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     Return YES; // for supported orientations
    //otherwise return (interfaceOrientation == UIInterfaceOrientationLandscape); if you want only landscape mode.
}

或者如果你想布局子视图,我会做些什么呢?使用didRotateFromIntferfaceOrientation:如下所示:

Or what i would do in your situation if you want to layout your subviews is use the didRotateFromIntferfaceOrientation: like so:

(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    [self layoutSubviews];
}

以及layoutSubviews

and also layoutSubviews

- (void)layoutSubviews
{
    NSLog(@"layoutSubviews called");

    ...recalc rects etc based on the new self.view.bounds...
}

就像这样。

PK

这篇关于pop over view的定位问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:48