QQ聊天界面注意点

2/28

// 退出键盘
[self.messageField resignFirstResponder]
[self.messageField endEditing:YES]
[self.view endEditing:YES]; // 推荐

// 叫出键盘
[self.messageField becomeFirstResponder]

UIKeyboardWillChangeFrameNotification

设置按钮内子控件的设置:

// 不要直接拿出按钮内部的子控件,来修改文字、图片属性
self.title.text = @"XXX"; // 这样写是不对的

// 设置按钮内部的子控件的应该这样设置
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
// 设置按钮的文字

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
// 设置按钮的文字颜色

- (void)setImage:(UIImage *)image forState:(UIControlState)state;
// 设置按钮内部的小图片

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
// 设置按钮的背景图片

设置自定义按钮内子控件的frame

  • 调用layoutSubviews方法
- (void)layoutSubviews{
    // 这一句千万不能少
    [super layoutSubviews];

}

通知叫出键盘

- (void)viewDidLoad {
    [super viewDidLoad];

    // 设置文本框左边的内容
    UIView *leftView = [[UIView alloc] init];
    leftView.frame = CGRectMake(0, 0, 10, 0);
    self.messageField.leftView = leftView;
    self.messageField.leftViewMode = UITextFieldViewModeAlways;

    // 监听键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 键盘处理
- (void)keyboardWillChangeFrame:(NSNotification *)note {
    // 取出键盘最终的frame
    CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    // 取出键盘弹出需要花费的时间
    double duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    // 修改transform
    [UIView animateWithDuration:duration animations:^{
        CGFloat ty = [UIScreen mainScreen].bounds.size.height - rect.origin.y;
        self.view.transform = CGAffineTransformMakeTranslation(0, - ty);
    }];
}

transform

// transform:形变属性,能完成的功能:平移、缩放、旋转
[UIView animateWithDuration:2.0 animations:^{
    // 缩放
    self.tempView.transform = CGAffineTransformMakeScale(0.5, 0.5);
    // 平移
    self.tempView.transform = CGAffineTransformMakeTranslation(-100, 100);
    // 旋转
    self.tempView.transform = CGAffineTransformMakeRotation(-M_PI_4);

    // 平移 + 缩放 + 旋转
    CGAffineTransform translation = CGAffineTransformMakeTranslation(-100, 100);
    // 累加,传一个transform,再累加一个新的transfrom
    CGAffineTransform scaleTranslation = CGAffineTransformScale(translation, 0.5, 0.5);
    CGAffineTransform rotateScaleTranslation = CGAffineTransformRotate(scaleTranslation, M_PI_2);
    self.tempView.transform = rotateScaleTranslation;
}];
    // 累加,传一个transform,再累加一个新的transfrom
    [UIView animateWithDuration:1.0 animations:^{
        self.tempView.transform = CGAffineTransformScale(self.tempView.transform, 0.8, 0.8);
        self.tempView.transform = CGAffineTransformRotate(self.tempView.transform, M_PI_4);
    }];
// 清空transform,以前的平移、缩放、旋转都会消失
[UIView animateWithDuration:2.0 animations:^{
    self.tempView.transform = CGAffineTransformIdentity;

}];

图片拉伸(不用代码实现)

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值