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

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

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 有明确的可衡量的目标,持续专注的练习,不断反馈改进,不断突破自己的极限,从而成为某一领域的顶级高手,这个过程就是刻...
    闵语兰心阅读 1,198评论 6 31
  • 蝉 王汉文 我每天都兴高采烈的鸣唱 仿佛从来就没有过忧伤 爱听的鸟儿每天守在我身旁 不爱听的鸟儿飞向远方 还有吃饱...
    王汉文阅读 549评论 5 6