cocoa touch——UIView——draw
来源:互联网 发布:美工基础知识培训 编辑:程序博客网 时间:2024/04/29 07:00
draw
- (void)drawRect:(CGRect)rect;- (void)setNeedsDisplay;- (void)setNeedsDisplayInRect:(CGRect)rect;@property(nonatomic) BOOL clipsToBounds; // When YES, content and subviews are clipped to the bounds of the view. Default is NO.
注意:rect参考自身坐标系
演示
@interface FBView : UIView@end@implementation FBView- (void)drawRect:(CGRect)rect{ NSLog(@"drawRect rect = %@", NSStringFromCGRect(rect));}@end
- (void)viewDidLoad{ [super viewDidLoad]; NSLog(@"viewDidLoad"); fbView = [[FBView alloc] initWithFrame:CGRectMake(10, 20, 100, 200)]; fbView.contentMode = UIViewContentModeRedraw; [self.view addSubview:fbView];}- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; NSLog(@"viewWillAppear");}- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; NSLog(@"viewDidAppear");}
output:
viewDidLoadviewWillAppeardrawRect rect = {{0, 0}, {100, 200}}viewDidAppear
first display(draw)位于viewViewAppear和viewDidAppear之间
draw不要直接调用,下列情况会发生draw调用:
- first display
- 调用setNeedsDisplay或setNeedsDisplayInRect
- contentMode为UIViewContentModeRedraw,bounds change
分析:
UIView有一个draw flag和draw rect,默认draw flag为YES,draw rect为bounds,调用draw以后,draw flag设为NO,setNeedDisplay和setNeedsDisplayInRect就是设置draw flag和draw rect的(setNeedDisplay设置draw rect为bounds),当contentMode为UIViewContentModeRedraw,bounds change时,本质就是调用setNeedDisplay
0 0
- cocoa touch——UIView——draw
- cocoa touch——UIImage——attribute,draw
- cocoa touch——UIView——frame bounds center
- cocoa touch——UIView——autoresizing
- cocoa touch——UIView——NSLayoutAnchor
- cocoa touch——UIView——backgroundColor,tintColor
- cocoa touch——UILabel
- cocoa touch——UIImageView
- cocoa touch——UISwitch
- cocoa touch——UIProgressView
- cocoa touch——UIActivityIndicatorView
- cocoa touch——UIPageControl
- cocoa touch——UIPickerView
- cocoa touch——NSLayoutAnchor
- cocoa touch——NSLayoutConstraint
- cocoa touch——UIView——superview subviews window tag
- IOS学习之——Cocoa 和Cocoa Touch
- cocoa touch——UIViewController——生命周期
- OMNeT++批量仿真
- PHP超大文件下载,断点续传下载
- 二零一三年计算机视觉代码合集
- 关于java布局
- 【华为oj】扑克牌比较
- cocoa touch——UIView——draw
- UIView——动画
- 图像高斯分布生成
- thinkphp3.2.3无法加载新建控制器:User
- SystemVerilog中结合interface实现输出数据总线的功能(1)
- TortoiseSVN服务器ip地址修改后如何使用
- 标准IO与文件IO 的区别
- Oracle -- 索引
- pdf2swf 转换时报错