zoukankan      html  css  js  c++  java
  • 键盘盖住输入框问题,包含中英文切换

    只是修改了官方的demo

    - (void)viewDidLoad

    {

        [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

        

        

        [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:)  name:UIKeyboardWillShowNotificationobject:nil];

        [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotificationobject:nil]; 

        inputview=[[UITextViewalloc] initWithFrame:CGRectMake(123,750, 111,44)];

        [inputviewsetBackgroundColor:[UIColorredColor]];

        [self.view addSubview:inputview];

    }

    - (void)didReceiveMemoryWarning

    {

        [superdidReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

        

    }

    - (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView {

        

        if (inputview.inputAccessoryView == nil) {

            [[NSBundlemainBundle] loadNibNamed:@"AccessoryView"owner:selfoptions:nil];

        }

        

        returnYES;

    }

    - (BOOL)textViewShouldEndEditing:(UITextView *)aTextView {

        [aTextView resignFirstResponder];

        returnYES;

    }

    #pragma mark -

    #pragma mark Responding to keyboard events

    - (void)keyboardWillShow:(NSNotification *)notification {    

        NSDictionary *userInfo = [notification userInfo]; 

        NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

        CGRect keyboardRect = [aValue CGRectValue];

        NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

        NSTimeInterval animationDuration;

        [animationDurationValue getValue:&animationDuration];

        [UIViewbeginAnimations:nilcontext:NULL];

        [UIView setAnimationDuration:animationDuration];    

        inputview.frame=CGRectMake(123,keyboardRect.origin.y-64, 111,44);

        [UIViewcommitAnimations];

    }

    - (void)keyboardWillHide:(NSNotification *)notification {

        

        NSDictionary* userInfo = [notification userInfo];

        NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

        NSTimeInterval animationDuration;

        [animationDurationValue getValue:&animationDuration];    

        [UIViewbeginAnimations:nilcontext:NULL];

        [UIView setAnimationDuration:animationDuration];    

        inputview.frame = CGRectMake(123,750, 111,44);    

        [UIViewcommitAnimations];

    }

  • 相关阅读:
    COGS 14. [网络流24题] 搭配飞行员
    洛谷 P3376 【模板】网络最大流
    洛谷 P2936 [USACO09JAN]全流Total Flow
    codevs 2038 香甜的黄油 USACO
    codevs 1993 草地排水 USACO
    Openjudge 2.5 6264:走出迷宫
    洛谷 P1744 采购特价商品
    HDU
    中国剩余定理
    bzoj2157: 旅游
  • 原文地址:https://www.cnblogs.com/sgdkg/p/2875435.html
Copyright © 2011-2022 走看看