美文网首页
持续记录iOS中常用的小技巧

持续记录iOS中常用的小技巧

作者: QYiZHong | 来源:发表于2018-03-27 12:44 被阅读21次

    每次写的时候总是忘,最后还得去之前的代码翻出来,所以干脆就找个地方记下来

    tableview去除分割线

    self.separatorStyle = UITableViewCellSeparatorStyleNone;
    

    点击cell的动画

    [tableView deselectRowAtIndexPath:indexPath animated:true];
    

    监听键盘弹出和放下

    - (void)willShowKeyboard:(NSNotification *)notification {
    CGFloat durition = [notification.userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] doubleValue];
    CGRect keyboardRect = [notification.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
    CGFloat keyboardHeight = keyboardRect.size.height;
    
    [UIView animateWithDuration:durition animations:^{
        self.bottomView.transform = CGAffineTransformMakeTranslation(0, -keyboardHeight);
    }];
    }
    
    - (void)willHideKeyboard:(NSNotification *)notification {
    CGFloat duration = [notification.userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] doubleValue];
    [UIView animateWithDuration:duration animations:^{
        self.bottomView.transform = CGAffineTransformIdentity;
    }completion:^(BOOL finished) {
        [UIView animateWithDuration:0.5f animations:^{
            self.okBtn.alpha = 1;
            self.bottomView.alpha = 0;
        }];
    }];
    }
    

    判断代理有没有写

    - (BOOL)respondsToSelector:(SEL)aSelector;
    

    高逼格通知写法

    .h文件里

    UIKIT_EXTERN NSNotificationName const MessageFieldDidChangeNotification;
    

    .m文件里

    NSNotificationName const MessageFieldDidChangeNotification = @"MessageFieldDidChangeNotification";
    

    category里加上自定义的属性,比如说做一个自定义的navigationBar

    //声明属性
    @property(strong,nonatomic)YZNavigationBar *yzNavigationBar;
    
    //自己实现getter方法
    - (YZNavigationBar*)yzNavigationBar{
    return objc_getAssociatedObject(self, @selector(yzNavigationBar));
    }
    
    //自己实现setter方法
    - (void)setYzNavigationBar:(YZNavigationBar *)yzNavigationBar{
    objc_setAssociatedObject(self, @selector(yzNavigationBar), yzNavigationBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    

    VC里自带的转场动画

    @property(nonatomic,assign) UIModalTransitionStyle modalTransitionStyle NS_AVAILABLE_IOS(3_0);
    typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
    UIModalTransitionStyleCoverVertical = 0,
    UIModalTransitionStyleFlipHorizontal __TVOS_PROHIBITED,
    UIModalTransitionStyleCrossDissolve,
    UIModalTransitionStylePartialCurl NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
    };
    

    视图部分圆角

    - (void)changeBottomViewCornerRadius {
      [self layoutIfNeeded];
      UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bottomView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(18, 18)];
      CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
      maskLayer.frame = self.bottomView.bounds;
      maskLayer.path = maskPath.CGPath;
      self.bottomView.layer.mask = maskLayer;
    }
    

    viewcontroller跳转

    modalPresentationStyle
    modalTransitionStyle

    相关文章

      网友评论

          本文标题:持续记录iOS中常用的小技巧

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