一切都回到用户界面
这个警告可以针对几个不同的对象实现:选择器、键盘等。
我发现它与 UI 采取两个步骤来完成过渡或其他动画有关。或者对于 UI 试图完成一件事并被要求在完成之前执行另一件事的任何情况。 (因此它涵盖了广泛的可能触发因素)
我已经看到警告出现在 4.0 和 4.2 上。在我的情况下,我正在旋转设备并捕捉键盘是否仍然向上(即文本字段仍然是第一响应者)。如果是这样,键盘需要在视图之间保持不变,但这会给其他视图带来其他复杂性。
因此,我实现了一个 BOOL 跟踪器来跟踪 keybaordIsPresent,如果是,我是 {textfield resignFirstResponder];当检测到方向变化并在包含在动画块中的转换之后将文本字段重置为 becomeFristResponder 时。我的 BOOL 跟踪器工作得更好,我仍然使用键盘的 NSNotifications,但是在旋转过程中通知重叠,因为键盘在没有请求的情况下被关闭。 BOOL 在加载时设置为 NO,并且当 [textfield resignFirstResponder];被实施。 *不是当“-(void)keyboardWillhide 由 NSNotifications 触发时,这给了我两个从不冲突的工作触发器。BOOL 设置为 YES,只有当用户触摸自动触发 becomeFirstResponder 的文本字段时。
我通过使用 [textfild resignFirstResponder] 删除了警告;走出去
-(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//if (keyboardIsPresent == YES) {[self.entryTextField resignFirstResponder];}
}
并将其放回代码的顶部:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if (keyboardIsPresent == YES) {
[self.entryTextField resignFirstResponder];
}
//Determine Which Orientation is Present:
if((fromInterfaceOrientation == UIInterfaceOrientationPortrait) || (fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
//LANDSCAPE VIEW:
[self configureLandscapeView];
}else {
//PORTRAIT VIEW:
[self configurePortraitView];
}
}
**即使我在 -(void)willAnimatFirstHalfOfRotationToInterface: 中没有代码,警告仍然会弹出。我认为警告仍在弹出,因为编译器在尝试执行第一个动画时仍然必须尝试该方法,因此会获得双重动画调用或资源重叠。它不知道该方法没有可执行代码,直到它运行之后。到那时,它已经预留了资源以准备处理方法中可能的操作。
**为了消除警告,我必须删除或取消 willAnimateFirstHalfOfRotation 的代码,这样编译器甚至不必检查是否有可能需要同时执行的第二个动画或动作.
/*-(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//if (keyboardIsPresent == YES) {[self.entryTextField resignFirstResponder];}}*/
转换完成后,在原始动画块中,我检查“keyboardIsPresent”在旋转之前是否为 YES,如果是,我再次辞去 First Responder 的职务。我使用setAnimationDuration:0.3,它非常干净而且不跳动。