5
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
- (void)keyboardWillShow:(NSNotification *)aNotification {
UIInterfaceOrientation orientation = ((UIViewController*)delegate).interfaceOrientation;
[UIView beginAnimations:@"viewSlideUp" context:NULL];
UIView *view = [delegate viewForUseWithTool:self];
CGRect frame = [view frame];
switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
frame.origin.x -= viewSlideDistance;
break;
case UIInterfaceOrientationLandscapeRight:
frame.origin.x += viewSlideDistance;
break;
case UIInterfaceOrientationPortrait:
frame.origin.y -= viewSlideDistance;
break;
case UIInterfaceOrientationPortraitUpsideDown:
frame.origin.y += viewSlideDistance;
break;
default:
break;
}
[view setFrame:frame];
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)aNotification {
UIInterfaceOrientation orientation = ((UIViewController*)delegate).interfaceOrientation;
[UIView beginAnimations:@"viewSlideDown" context:NULL];
UIView *view = [delegate viewForUseWithTool:self];
CGRect frame = [view frame];
switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
frame.origin.x += viewSlideDistance;
break;
case UIInterfaceOrientationLandscapeRight:
frame.origin.x -= viewSlideDistance;
break;
case UIInterfaceOrientationPortrait:
frame.origin.y += viewSlideDistance;
break;
case UIInterfaceOrientationPortraitUpsideDown:
frame.origin.y -= viewSlideDistance;
break;
default:
break;
}
[view setFrame:frame];
[UIView commitAnimations];
}
当我们编辑完了内容后 我们可以点击屏幕的其他地方(我们设置了[dudelView endEditing:YES]) 或者点击键盘上的落下键盘按钮 这时 进入textView的 delegate
1
2
3
4
5
6
7
8
9
10
11
- (void)textViewDidEndEditing:(UITextView *)textView {
//NSLog(@"textViewDidEndEditing");
TextDrawingInfo *info = [TextDrawingInfo textDrawingInfoWithPath:completedPath text:textView.text strokeColor:delegate.strokeColor font:delegate.font];
[delegate addDrawable:info];
self.completedPath = nil;
UIView *superView = [textView superview];
[[superView viewWithTag:SHADE_TAG] removeFromSuperview];
[textView resignFirstResponder];
[textView removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
这里 用到了一个新类TextDrawingInfo 同上一章 的PathDrawingInfo 类似,都是 存放一个完整操作的 全部信息,由于上一章我们做的是绘图操作,因此PathDrawingInfo 存放的是每次绘图操作的信息, 而这次我们主要向利用coreText在屏幕上显示文字 那么之前绘制的矩形的信息 此时已经没有用 我门要 取得 CoreText 需要的信息,即我们这次文字操作的信息 存到TextDrawingInfo 中去 并且添加到 dudelView 的 drawables中 最后 将没用的东西全部从屏幕上移除
最后看以下 TextDrawingInfo 中的draw方法是怎么把文字绘制上去的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- (void)draw {
CGContextRef context = UIGraphicsGetCurrentContext();
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:se