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

在iOS 8.1之后,在所有设备上,当点击alertview取消按钮时,ScrollView会向上移动,而不会滚动,ios,objective-c,iphone,uiscrollview,ios8.3,Ios,Objective C,Iphone,Uiscrollview,Ios8.3,我有一个登录屏幕,其中有两个用户名和密码文本字段。当电子邮件不正确时,我向下移动键盘,为用户显示相应的警报。当我点击alertview的cancel按钮时,alert view消失,scroll view向上移动。此问题仅出现在iOS 8.1之后的设备上。在iOS 8.1及更早版本上,它运行良好。我不明白确切的原因是什么?下面是代码 -(BOOL)textFieldShouldReturn:(UITextField *)textField{ if (txtActiveField ==

我有一个登录屏幕,其中有两个用户名和密码文本字段。当电子邮件不正确时,我向下移动键盘,为用户显示相应的警报。当我点击alertview的cancel按钮时,alert view消失,scroll view向上移动。此问题仅出现在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];
}
-(BOOL)textField应返回:(UITextField*)textField{
if(txtActiveField==txtUsername){
[TXT密码成为第一响应者];
}
else if(txtActiveField==txtPassword){
[txtPassword resignFirstResponder];
//[自我登录邮箱:self];
[self-performSelector:@selector(loginViaEmail:)with object:btnLogin afterDelay:0.0];
}
返回YES;}
-(iAction)登录邮箱:(id)发件人{
//[txtActiveField辞职FirstResponder];
如果([[txtUsername.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@”“]]长度]==0)
{
[AppDelegate showWithTitle:title消息:@“请输入您帐户的用户名/电子邮件”];
}
else if([txtPassword.text长度]<6)
{
如果([[txtPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@”“]]长度]==0)
[AppDelegate showWithTitle:标题消息:@“请输入密码”];
其他的
[AppDelegate showWithTitle:标题消息:@“密码至少包含6个字符”];
}
#pragma标记显示带有消息的警报
+(无效)showWithTitle:(NSString*)标题消息:(NSString*)消息
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:title消息:消息委托:nil cancelButtontile:@“确定”其他Buttontiles:nil];
[警报显示];
}

我认为这是警报视图的问题。从iOS 8开始,警报视图控制器取代了警报视图。请尝试使用以下代码,这些代码在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];
    }
}