iOS 8.1之后,在所有设备上,当点击alertview取消按钮时,ScrollView会向上滚动,而不会滚动



我有一个登录屏幕,其中有两个文本字段的用户名和密码。当电子邮件是不正确的,然后我向下移动键盘,并显示适当的提醒用户。当我点击alertview的取消按钮,然后警报视图消失,滚动视图向上。这个问题只会出现在iOS 8.1之后的设备上。在iOS 8.1及更早版本上,它运行良好。我不明白确切的原因是什么?下面是代码

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (txtActiveField == txtUsername) {
        [txtPassword becomeFirstResponder];
    }
    else if (txtActiveField == txtPassword) {
        [txtPassword resignFirstResponder];
        //[self loginViaEmail:self];
        [self performSelector:@selector(loginViaEmail:) withObject:btnLogin afterDelay:0.0];
    }
    return YES;}
-(IBAction)loginViaEmail:(id)sender{
    //[txtActiveField resignFirstResponder];
    if ([[txtUsername.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]] length] == 0)
    {
        [AppDelegate showWithTitle:title message:@"Please enter Username/Email for your account"];
    }
    else if ([txtPassword.text length] < 6)
    {
        if([[txtPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]] length] == 0)
            [AppDelegate showWithTitle:title message:@"Please enter Password"];
        else
            [AppDelegate showWithTitle:title message:@"Password contain minimum 6 characters"];
    }

#pragma mark Show alert with message
+(void)showWithTitle:(NSString *)title message:(NSString *)msg
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

我认为这是Alert视图的问题。从iOS 8开始,AlertViewController取代了警报视图。下面的代码在iOS 8.4及以下版本

上运行良好
if (IS_OS_8_OR_LATER) {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction
                                     actionWithTitle:@"OK"
                                     style:UIAlertActionStyleCancel
                                     handler:^(UIAlertAction *action)
                                     {
                                     }];
        [alertVC addAction:cancelAction];
        [[[[[UIApplication sharedApplication] windows] objectAtIndex:0] rootViewController] presentViewController:alertVC animated:YES completion:^{
        }];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
}

相关内容

  • 没有找到相关文章

最新更新