《iOS 编程》5. 视图:重绘与 UIScrollView

5.1 运行循环和重绘原理

iOS 每次事件处理周期中只发送一次 drawRect: 消息。所以视图要重绘必须向其发送 setNeedDisplay 消息。

5.3 使用 UIScrollView

添加子视图,设置大小即可。类似一张大的画布,可以方便移动局部查看。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

CGRect screenRect = self.window.bounds;
CGRect bigRect = screenRect;
bigRect.size.width *= 2.0;

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
[scrollView setPagingEnabled:YES];
[self.window addSubview:scrollView];


GWHypnosisView *hypnosisView = [[GWHypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:hypnosisView];

screenRect.origin.x += screenRect.size.width;
GWHypnosisView *anotherView = [[GWHypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:anotherView];


scrollView.contentSize = bigRect.size;

项目代码保存在我的 GitHub: iOSProgramming4edSolutions