Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios6 单击时设置文本框动画_Ios6_Uitextfield - Fatal编程技术网

Ios6 单击时设置文本框动画

Ios6 单击时设置文本框动画,ios6,uitextfield,Ios6,Uitextfield,我试图在iPad应用程序中从屏幕底部移动一个文本框,这样键盘就不会覆盖它 我有以下几种方法可以奏效 -(void) textViewDidBeginEditing:(UITextView *) observationComment { observationComment.frame=CGRectMake(190, 100, 700, 250); } 但是1-我想动画的运动-这是可能的吗 2-我收到一个警告 Local declaration of 'observationComment' h

我试图在iPad应用程序中从屏幕底部移动一个文本框,这样键盘就不会覆盖它

我有以下几种方法可以奏效

-(void) textViewDidBeginEditing:(UITextView *) observationComment
{
observationComment.frame=CGRectMake(190, 100, 700, 250);
}
但是1-我想动画的运动-这是可能的吗

2-我收到一个警告

Local declaration of 'observationComment' hides instance variable
有什么建议吗?也许这不是最好的方法。

我以前发现过,但我必须添加代码,以便当用户按globe键在键盘(如国际或表情符号)之间切换时,视图控制器的View.frame可以进行调整()

在YourViewController.h中,将键盘的高度(仅当它可见时)存储在实例变量中

@interface YourViewController : UIViewController {
    CGFloat keyboardHeightIfShowing ;
}
在YourViewController.m中,实现这些方法

- (void) keyboardWillShow:(NSNotification*)notification {
    [self moveTextViewForKeyboard:notification up:YES] ;
}

- (void) keyboardWillHide:(NSNotification*)notification {
    [self moveTextViewForKeyboard:notification up:NO] ;
}

- (void) moveTextViewForKeyboard:(NSNotification*)notification up:(BOOL)up {
    NSDictionary* userInfo = [notification userInfo] ;
    UIViewAnimationCurve animationCurve ;
    NSTimeInterval animationDuration ;
    CGRect keyboardEndFrame ;

    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve] ;
    [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration] ;
    [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame] ;

    [UIView beginAnimations:nil context:nil] ;
    [UIView setAnimationDuration:animationDuration] ;
    [UIView setAnimationCurve:animationCurve] ;

    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil] ;
    //Since I have a UITabBar, when the keyboard appears, self.view.frame.height should shrink by slightly less than if I did not have a UITabBar.
    keyboardFrame.size.height -= self.tabBarController.tabBar.frame.size.height ;
    CGRect newViewFrame = self.view.frame ;
    //UIKeyboardWillShowNotification can be triggered even when the keyboard is already showing, such as when switching between certain international keyboards. When this happens, before shrinking newViewFrame to accommodate keyboardFrame, enlarge newViewFrame so that it is the size it was before the previous keyboard appeared.
    if ( up && keyboardHeightIfShowing ) {
        NSLog(@"hiding keyboard with height %0.1f, showing keyboard with height %0.1f",keyboardHeightIfShowing, keyboardFrame.size.height) ;
        newViewFrame.size.height += keyboardHeightIfShowing ;
    }
    newViewFrame.size.height -= keyboardFrame.size.height * (up ? 1 : -1) ;
    keyboardHeightIfShowing = ( up ? keyboardFrame.size.height : 0 ) ;
    self.view.frame = newViewFrame ;

    [UIView commitAnimations] ;
}
最后,在YourViewController.m中,建立要由UIKeyboard调用的
keyboardWillShow
keyboardWillHide

- (void) viewWillAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil] ;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil] ;
}

- (void) viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil] ;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil] ;
}
我以前发现过,但我必须添加代码,以便当用户通过按globe键()在键盘(如international或emoji)之间切换时,视图控制器的View.frame可以进行调整

在YourViewController.h中,将键盘的高度(仅当它可见时)存储在实例变量中

@interface YourViewController : UIViewController {
    CGFloat keyboardHeightIfShowing ;
}
在YourViewController.m中,实现这些方法

- (void) keyboardWillShow:(NSNotification*)notification {
    [self moveTextViewForKeyboard:notification up:YES] ;
}

- (void) keyboardWillHide:(NSNotification*)notification {
    [self moveTextViewForKeyboard:notification up:NO] ;
}

- (void) moveTextViewForKeyboard:(NSNotification*)notification up:(BOOL)up {
    NSDictionary* userInfo = [notification userInfo] ;
    UIViewAnimationCurve animationCurve ;
    NSTimeInterval animationDuration ;
    CGRect keyboardEndFrame ;

    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve] ;
    [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration] ;
    [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame] ;

    [UIView beginAnimations:nil context:nil] ;
    [UIView setAnimationDuration:animationDuration] ;
    [UIView setAnimationCurve:animationCurve] ;

    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil] ;
    //Since I have a UITabBar, when the keyboard appears, self.view.frame.height should shrink by slightly less than if I did not have a UITabBar.
    keyboardFrame.size.height -= self.tabBarController.tabBar.frame.size.height ;
    CGRect newViewFrame = self.view.frame ;
    //UIKeyboardWillShowNotification can be triggered even when the keyboard is already showing, such as when switching between certain international keyboards. When this happens, before shrinking newViewFrame to accommodate keyboardFrame, enlarge newViewFrame so that it is the size it was before the previous keyboard appeared.
    if ( up && keyboardHeightIfShowing ) {
        NSLog(@"hiding keyboard with height %0.1f, showing keyboard with height %0.1f",keyboardHeightIfShowing, keyboardFrame.size.height) ;
        newViewFrame.size.height += keyboardHeightIfShowing ;
    }
    newViewFrame.size.height -= keyboardFrame.size.height * (up ? 1 : -1) ;
    keyboardHeightIfShowing = ( up ? keyboardFrame.size.height : 0 ) ;
    self.view.frame = newViewFrame ;

    [UIView commitAnimations] ;
}
最后,在YourViewController.m中,建立要由UIKeyboard调用的
keyboardWillShow
keyboardWillHide

- (void) viewWillAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil] ;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil] ;
}

- (void) viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil] ;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil] ;
}
看看或者。这是一个复杂的问题,但这些应该会让你更好地了解你需要做什么。

看看或。这是一个复杂的问题,但这些应该让你更好地了解你需要做什么