zoukankan      html  css  js  c++  java
  • 全局异步和主线程异步区别、改变PlaceHolder颜色、解决键盘弹起挡住文本框问题

    1、全局异步执行耗时任务

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

    });

    2.主线程异步刷新UI

    dispatch_async(dispatch_get_main_queue(), ^{

    });

    3.改变PlaceHolder的颜色

    [username_text setValue:[UIColor colorWithRed:1 green:1

    blue:1 alpha:0.5]

    forKeyPath:@"_placeholderLabel.textColor"];

    4.解决键盘弹起挡住文本框的问题

    //键盘弹起时重置View大小

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent

    *)event{

    [username_text resignFirstResponder];

    [password_text resignFirstResponder];

    NSTimeInterval animationDuration = 0.30f;

    [UIView beginAnimations:@"ResizeForKeyboard"context:nil];

    [UIView setAnimationDuration:animationDuration];

    CGRect rect = CGRectMake(0.0f, 0.0f,self.view.frame.size.width,self.view.frame.size.height);

    self.view.frame = rect;

    [UIView commitAnimations];

    }

    //退出编辑(键盘落下)重置View大小

    - (BOOL)textFieldShouldReturn:(UITextField *)textField

    {

    NSTimeInterval animationDuration = 0.30f;

    [UIView beginAnimations:@"ResizeForKeyboard"context:nil];

    [UIView setAnimationDuration:animationDuration];

    CGRect rect = CGRectMake(0.0f, 0.0f,self.view.frame.size.width,self.view.frame.size.height);

    self.view.frame = rect;

    [UIView commitAnimations];

    [textField resignFirstResponder];

    return YES;

    }

    5.开始编辑(键盘弹起)通过控件Y坐标计算View显示范围

    - (void)textFieldDidBeginEditing:(UITextField *)textField

    {

    CGRect frame = password_text.frame;

    int offset = frame.origin.y + 32 -

    (self.view.frame.size.height - 216.0);

    NSTimeInterval animationDuration = 0.30f;

    [UIView beginAnimations:@"ResizeForKeyBoard"

    context:nil];

    [UIView setAnimationDuration:animationDuration];

    floatwidth =self.view.frame.size.width;

    floatheight =self.view.frame.size.height;

    if(offset > 0)

    {

    CGRect rect = CGRectMake(0.0f, -

    offset,width,height);

    self.view.frame = rect;

    }

    [UIView commitAnimations];

    }

  • 相关阅读:
    MySQL数据库服务器的架设
    Ubuntu 16.04 LTS软件包管理基本操作
    2个 List<T>进行数据合并
    创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或
    【转】.gitignore失效的解决办法
    【转】码农提高工作效率
    【转】从零开始编写自己的C#框架(7)——需求分析
    C#获取文件的绝对路径
    【转】类中如何引用server.MapPath()
    c# 运行时替换某文件源代码(将XML 转换成 某个枚举并写入源文件)
  • 原文地址:https://www.cnblogs.com/CJH5209/p/6072129.html
Copyright © 2011-2022 走看看