• 键盘盖住输入框问题,包含中英文切换


    只是修改了官方的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];

    }

  • 相关阅读:
    哪种写法更好?<script></script> vs/or <script type=”text/javasript”></script>
    JS 脚本应该放在页面哪个位置 head body foot
    List<T> ForEach break
    嵌套JSON 取出name与value
    C# 改变图片尺寸(压缩),Image Resize
    tornado
    appachebench网站压力测试
    mysql分区分表
    redis的持久化存储,RDB与AOF
    MEMCACHE的内存管理和删除策略
  • 原文地址:https://www.cnblogs.com/sgdkg/p/2875435.html
Copyright © 2020-2023  润新知