Dis*_*ame 8 objective-c screen-orientation uipopover
我为iOS7开发了一个应用程序,现在尝试为iOS8更新它.问题我有以下几点:
应用程序屏幕方向可以旋转,在某些情况下,一些按钮会大幅移动.我有一些指向这些按钮的弹出窗口,所以如果在屏幕旋转时弹出窗口,按钮移动,我也需要弹出窗口.
在iOS7中我通过以下方式做到了这一点:当屏幕旋转时我更新了约束
- (void) updateViewConstraints
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
self.Button.constant = (CGFloat)10;
}
else
{
self.Button.constant = (CGFloat)5;
}
[super updateViewConstraints];
}
Run Code Online (Sandbox Code Playgroud)
我也移动了弹出窗口
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
if(TempDisplayPopoverController == examplePopoverController)
{
[examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
我最初加载弹出窗口
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
[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];
}
Run Code Online (Sandbox Code Playgroud)
但不知道如何解决popover问题.我试过了
popoverController: willRepositionPopoverToRect: inView:
Run Code Online (Sandbox Code Playgroud)
但似乎无法让它发挥作用.
谁能建议
谢谢
小智 1
使用 时popoverController:willRepositionPopoverToRect:inView:,重新分配给rect参数时,请尝试使用:
*rect = myNewRect;
Run Code Online (Sandbox Code Playgroud)
并不是:
rect = &presentingRect;
Run Code Online (Sandbox Code Playgroud)
另外,请确保您已正确分配弹出窗口控制器的委托。