1.初始化:
- 对于在程序中创建的View,重写initWithFrame初始化。 - 对于在nib中载入的View,重写initWithCoder初始化。 - 在nib文件载入完成后,可以使用awakeFromNib处理其他初始化操作。awakeFromNib在initWithCoder之后执行。 注意要使用[super initXXX]来调用父类的初始化函数。 2.重写dealloc析构。注意要使用[super dealloc]. 3.重写drawRect实现绘制。 4.设置autoresizingMask来设置View大小改变时的自动操作。 5.对于subView - 在初始化函数里创建。 - 设置autoresizingMask。 - 重写layoutSubviews实现布局。 6.使用addGestureRecognizer来添加手势识别对象,重写 - touchesBegan - touchesMoved - touchedEnded - touchedCancelled 来处理手势事件。 使用MultipleTouchEnable来打开多重手势。 使用UserInteactiveEnable来打开手势识别。 使用BeginIgnoringInteractionEvent和EndIgnoringInteractiveEvent来忽略当前事件。 使用hitTest和pointInside来检测手势是否发生在当前View中。 7. 使用DrawRect实现打印。
自定义View要做的事情
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot自定义starter
SpringBoot自定义starter
spring maven ci -
自定义View(二)、自定义View的分类及流程
上一篇对View的坐标位置等一些基础概念进行了介绍,这篇开始对自定义View的流程进行分析,后面再通过一个简单的实战来巩固
Android 自定义 android java