美文网首页
UIKit Some Attention Collections

UIKit Some Attention Collections

作者: cc_Jumper | 来源:发表于2020-07-08 16:15 被阅读0次

主要用于收集一些UIKit使用过程中,需要着重注意的一些点

  1. 如果想要将一个view从右边缩放展开,不能先进行缩放再平移,而是后者
    // 从maxX缩放展开1:先缩放后平移 ❌
    CGAffineTransform transform = CGAffineTransformMakeScale(CGFLOAT_MIN, 1);
    transform = CGAffineTransformTranslate(transform, 0.5 * CGRectGetWidth(self.bounds), 0);
    // 从maxX缩放展开2:先平移后缩放 ✅
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0.5 * CGRectGetWidth(self.bounds), 0);
    transform = CGAffineTransformScale(transform, CGFLOAT_MIN, 1);
    // 从maxX缩放展开3:可以结合anchorPoint来实现,但是要注意如果是autolayout布局相对位置也会受到影响
    CGAffineTransform transform = CGAffineTransformScale(transform, CGFLOAT_MIN, 1);
    self.layer.anchorPoint = CGPointMake(1, 0.5);
    self.layer.transform = transform;
    // 从centerX缩放展开
    CGAffineTransform transform = CGAffineTransformMakeScale(CGFLOAT_MIN, 1);

  // 开始动画
    self.transform = transform;
    [UIView animateWithDuration:0.25 animations:^{
        self.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        [self setUpTimer];
    }];
  1. Xib上面设置UIButton的对齐属性如:
    self.userCountBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentTrailing;
    在有些设备上面失效,是因为这个属性是iOS11才引入的。
    注意将xib上设置成UIControlContentHorizontalAlignmentRight即可


    image.png
typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {
    UIControlContentHorizontalAlignmentCenter = 0,
    UIControlContentHorizontalAlignmentLeft   = 1,
    UIControlContentHorizontalAlignmentRight  = 2,
    UIControlContentHorizontalAlignmentFill   = 3,
    UIControlContentHorizontalAlignmentLeading  API_AVAILABLE(ios(11.0), tvos(11.0)) = 4,
    UIControlContentHorizontalAlignmentTrailing API_AVAILABLE(ios(11.0), tvos(11.0)) = 5,
};
  1. iOS9系统,有时候会出现从后台回到前台,调用UIApplicationDidBecomeActiveNotification、UIApplicationWillResignActiveNotification、UIApplicationDidBecomeActiveNotification情况。
    可能原因是为了加快键盘出来速度或者是苹果的全局控制原点导致出现了UIRemoteKeyboardWindow,而调用多次的情况。
    如果只是想要监听前后台变化,使用UIApplicationWillEnterForegroundNotification、UIApplicationDidEnterBackgroundNotification代替;

相关文章

网友评论

      本文标题:UIKit Some Attention Collections

      本文链接:https://www.haomeiwen.com/subject/yupccktx.html