获取 UIPopoverBackgroundVisualEffectView 的警告
Getting warning for UIPopoverBackgroundVisualEffectView
我在我的视图中显示了一个 UIActionSheet
,其中一个操作 sheet 的按钮显示了另一个操作 sheet。当我在 iPad 上执行第二个操作 sheet 时,我在日志中收到此警告消息:
UIPopoverBackgroundVisualEffectView is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
这是我的代码:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Option"] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Sort", nil];
actionSheet.tag = 1;
[actionSheet showInView:self.view];
在委托中:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[self showSortAction];
}
-(void)showSortAction {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Sort By" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"A-Z", @"Z-A", @"Newer to older", @"Older to newer", nil];
actionSheet.tag = 2;
[actionSheet showInView:self.view];
}
我的猜测是第二个动作 sheet 的呈现导致第一个动作 sheet 的不透明度发生变化,从而触发您看到的警告。不要从 -actionSheet:clickedButtonAtIndex:
中调用 -showSortAction
,而是从 -actionSheet:didDismissWithButtonIndex:
中调用它。这使第一个动作 sheet 有足够的时间在第二个动作开始动画之前从屏幕上消失。(请参阅 UIActionSheetDelegate documentation – 具体来说,单击和 did-dismiss 方法的详细文本。 )
尽管我们讨论这个主题,但请注意 UIActionSheet documentation 表示它已从 iOS 8 开始弃用。除非您针对 iOS 7 或更早版本进行编程,考虑尽快过渡到 UIAlertController。
@Tim 以上是正确的。
您不应再使用已弃用的 UIActionSheet。他关于使用 actionSheet:didDismissWithButtonIndex:
的解决方案以前可能有效,但根据 它不再有效,因为 Apple 已转向 UIAlertController
。
您真的应该将代码切换为 UIAlertController
而不是旧方法来解决问题。
我在我的视图中显示了一个 UIActionSheet
,其中一个操作 sheet 的按钮显示了另一个操作 sheet。当我在 iPad 上执行第二个操作 sheet 时,我在日志中收到此警告消息:
UIPopoverBackgroundVisualEffectView is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
这是我的代码:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Option"] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Sort", nil];
actionSheet.tag = 1;
[actionSheet showInView:self.view];
在委托中:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[self showSortAction];
}
-(void)showSortAction {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Sort By" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"A-Z", @"Z-A", @"Newer to older", @"Older to newer", nil];
actionSheet.tag = 2;
[actionSheet showInView:self.view];
}
我的猜测是第二个动作 sheet 的呈现导致第一个动作 sheet 的不透明度发生变化,从而触发您看到的警告。不要从 -actionSheet:clickedButtonAtIndex:
中调用 -showSortAction
,而是从 -actionSheet:didDismissWithButtonIndex:
中调用它。这使第一个动作 sheet 有足够的时间在第二个动作开始动画之前从屏幕上消失。(请参阅 UIActionSheetDelegate documentation – 具体来说,单击和 did-dismiss 方法的详细文本。 )
尽管我们讨论这个主题,但请注意 UIActionSheet documentation 表示它已从 iOS 8 开始弃用。除非您针对 iOS 7 或更早版本进行编程,考虑尽快过渡到 UIAlertController。
@Tim 以上是正确的。
您不应再使用已弃用的 UIActionSheet。他关于使用 actionSheet:didDismissWithButtonIndex:
的解决方案以前可能有效,但根据 它不再有效,因为 Apple 已转向 UIAlertController
。
您真的应该将代码切换为 UIAlertController
而不是旧方法来解决问题。