【发布时间】:2014-11-29 05:14:04
【问题描述】:
我已经为 iOS7 开发了一个应用程序,现在正在尝试为 iOS8 更新它。 我遇到的问题如下:
应用程序的屏幕方向可以旋转,并且在某些情况下,一些按钮会大幅移动。我有一些指向这些按钮的弹出框,所以如果屏幕旋转时弹出框打开,按钮移动,我也需要弹出框。
在 iOS7 中,我通过以下方式做到了这一点: 当屏幕旋转时,我更新了约束
- (void) updateViewConstraints
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
self.Button.constant = (CGFloat)10;
}
else
{
self.Button.constant = (CGFloat)5;
}
[super updateViewConstraints];
}
我也移动了弹出框
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
if(TempDisplayPopoverController == examplePopoverController)
{
[examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
我最初加载弹出框
- (void) LoadPopover{
examplePopover = [[examplep alloc] initWithNibName:@"exampleP" bundle:nil];
[examplePopover setDelegate:self];
examplePopoverController = [[UIPopoverController alloc] initWithContentViewController: examplePopover];
[examplePopoverController setDelegate:self];
examplePopoverController.popoverContentSize = examplePopover.view.frame.size;
TempDisplayPopoverController = examplePopoverController;
if ([examplePopoverController isPopoverVisible])
{
[examplePopoverController dismissPopoverAnimated:YES];
}
else
{
[examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
[self ExamplePopoverPosition] 只是返回按钮位置。
这一切都很好,我很高兴,iPad 很高兴并且一切正常。
现在由于 iOS8,我必须更改一些位。
self.interfaceOrientation 已折旧
[examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
在didRotateFromInterfaceOrientation 中抛出错误
"Application tried to represent an active popover presentation: <UIPopoverPresentationController: 0x7bf59280>"
我已经设法通过
纠正self.interfaceOrientation
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self SetUpScreen:toInterfaceOrientation];
}
- (void) SetUpScreen:(UIInterfaceOrientation)toInterfaceOrientation{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.Button.constant = (CGFloat)10;
}
else
{
self.Button.constant = (CGFloat)5;
}
[super updateViewConstraints];
}
但不知道如何解决弹出框问题。我试过了
popoverController: willRepositionPopoverToRect: inView:
但似乎无法让它工作。
谁能给点建议
谢谢
【问题讨论】:
-
这里有同样的问题。我们必须问苹果...
-
你好,我还没有解决这个问题
-
这有什么更新吗?我有同样的问题
-
不幸的是还没有稳定的东西
-
以 UIView 的形式访问 xib 文件的内容,并在 updateViewConstraints stackoverflow.com/a/7814977/1546710 中更新框架
标签: objective-c screen-orientation uipopover