当我在ios8中改变视图框时UIViewController视图消失了



此代码在iOS 7中运行良好,但在XCode 6中运行时&iOS8模拟器,视图消失(UIViewController viewWillDisappear被调用)后,我对self.webview.frame做了一个小的改变。当我从动作表中选择"编辑"选项时,就会发生这种情况。然而,当我点击webView并通知/调用keyboardWillShow:时,它不会消失。这个UIViewController是由rootViewController用modalPresentationStyle:UIModalPresentationFormSheet呈现的。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Edit"]){
        [self switchModeTo:@"Edit"];
    }
}
- (void)switchModeTo:(NSString *)mode{
    if([mode isEqualToString:@"Edit"]){
        self.isEditMode = YES;
        [self.btnApply setHidden:NO];
        [self.btnMore setHidden:YES];
        CGRect frame = [self.webview frame];
        frame.origin.y = 44;
        frame.size.height = 492;
        [self.webview setFrame:frame];
    }
}
- (void)keyBoardWillShow:(NSNotification *)notif{
    [self switchModeTo:@"Edit"];
}

我有一个非常相似的问题。我试图呈现一个由动作表触发的模态视图控制器。模态视图被呈现,然后它被立即解散。

我创建了另一个测试用例,并收到了以下消息:

Warning: Attempt to present <ModalViewController: 0x78fbadd0>  on <MainViewController: 0x78fa71c0> which is already presenting (null)

结果是动作表单弹出窗口干扰了视图控制器呈现另一个模态视图控制器的能力。与您的示例一样,如果我从动作表以外的东西触发相同的代码(在我的情况下,按钮),它工作得很好。

为了解决这个问题,我简单地引入了一个小延迟,让动作表单弹出窗口有机会离开,如下例所示:

- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ( buttonIndex != actionSheet.cancelButtonIndex ) {
        [self performSelector:@selector(showModalView) withObject:nil afterDelay:0.3];
    }
}
- (void)showModalView
{
    ModalViewController* modalVC = [[ModalViewController alloc] init];
    [self presentViewController:modalVC animated:YES completion:nil];
}

最新更新