动画 KVC KVO

中间的提醒内容

指示器、HUD、遮盖、蒙板

半透明的指示器如何实现?

指示器的alpha = 1.0

指示器的背景色是半透明的

创建颜色

直接创建对应的颜色

+ (UIColor*)blackColor;// 0.0 white

+ (UIColor*)darkGrayColor;// 0.333 white

+ (UIColor*)lightGrayColor;// 0.667 white

+ (UIColor*)whiteColor;// 1.0 white

+ (UIColor*)grayColor;// 0.5 white

+ (UIColor*)redColor;// 1.0, 0.0, 0.0 RGB

+ (UIColor*)greenColor;// 0.0, 1.0, 0.0 RGB

+ (UIColor*)blueColor;// 0.0, 0.0, 1.0 RGB

+ (UIColor*)cyanColor;// 0.0, 1.0, 1.0 RGB

+ (UIColor*)yellowColor;// 1.0, 1.0, 0.0 RGB

+ (UIColor*)magentaColor;// 1.0, 0.0, 1.0 RGB

+ (UIColor*)orangeColor;// 1.0, 0.5, 0.0 RGB

+ (UIColor*)purpleColor;// 0.5, 0.0, 0.5 RGB

+ (UIColor*)brownColor;// 0.6, 0.4, 0.2 RGB

+ (UIColor*)clearColor;// 透明色

根据RGB组合创建颜色

+ (UIColor*)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;

渐变动画

方式1:头尾式

[UIViewbeginAnimations:nilcontext:nil];[UIViewsetAnimationDuration:2.0];/* 需要执行动画的代码 */[UIViewcommitAnimations];

方式2:block式

[UIViewanimateWithDuration:2.0delay:1.0options:kNilOptions animations:^{/* 需要执行动画的代码 */} completion:nil]// 1s后,再执行动画(动画持续2s)

按钮

自定义按钮:调整内部子控件的frame

方式1:实现titleRectForContentRect:和imageRectForContentRect:方法,分别返回titleLabel和imageView的frame

方式2:在layoutSubviews方法中设置

内边距

// 设置按钮内容的内边距(影响到imageView和titleLabel)@property(nonatomic)UIEdgeInsetscontentEdgeInsets;

// 设置titleLabel的内边距(影响到titleLabel)@property(nonatomic)UIEdgeInsetstitleEdgeInsets;

// 设置imageView的内边距(影响到imageView)@property(nonatomic)UIEdgeInsetsimageEdgeInsets;

图片拉伸

iOS5之前

// 只拉伸中间的1x1区域- (UIImage*)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;

iOS5开始

- (UIImage*)resizableImageWithCapInsets:(UIEdgeInsets)capInsets;

- (UIImage*)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode;

拷贝

实现拷贝的方法有2个

copy:返回不可变副本

mutableCopy:返回可变副本

普通对象实现拷贝的步骤

遵守NSCopying协议

实现-copyWithZone:方法

创建新对象

给新对象的属性赋值


KVC

全称:Key Value Coding(键值编码)

赋值

// 能修改私有成员变量- (void)setValue:(id)value forKey:(NSString*)key;- (void)setValue:(id)value forKeyPath:(NSString*)keyPath;

- (void)setValuesForKeysWithDictionary:(NSDictionary*)keyedValues;

取值

// 能取得私有成员变量的值

- (id)valueForKey:(NSString*)key;

- (id)valueForKeyPath:(NSString*)keyPath;

- (NSDictionary*)dictionaryWithValuesForKeys:(NSArray*)keys;


KVO

全称:Key Value Observing(键值监听)

作用:监听模型的属性值改变

步骤

添加监听器

// 利用b对象来监听a对象name属性的改变

[a addObserver:b forKeyPath:@"name"options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNewcontext:@"test"];

在监听器中实现监听方法

-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change    context:(void*)context{NSLog(@"%@ %@ %@ %@", object, keyPath, change, context);}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • VLC的集成和使用 VLC介绍 VLC Media Player (VideoLAN) 为 Windows、Lin...
    Pocket阅读 20,143评论 75 66
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 10,541评论 5 13
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 4,816评论 1 6
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 12,722评论 6 30
  • --- 仅记一个多月的公交时光 NO.1 一如既往,日子仍是水平线,不偏不倚,不惊不喜,似平似淡。福州的天气...
    Megan_Chen阅读 2,338评论 0 0

友情链接更多精彩内容