【发布时间】:2017-12-16 03:24:56
【问题描述】:
出于某种原因,我制作了一个自定义视图,覆盖它的 drawrect 方法,以绘制一些字符串和 img。就像这样:
@implementation WaterMarkView
- (void)drawRect:(CGRect)rect {
NSLog(@"drawRect");
NSString* test = @"This is a test string";
NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:22],
NSForegroundColorAttributeName:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0],
};
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
CGSize strsize = [[[NSAttributedString alloc] initWithString:test attributes:attributes] size];
CGRect screentBounds = [[UIScreen mainScreen] bounds];
[test drawAtPoint:CGPointMake((screentBounds.size.width - strsize.width)/2,
(screentBounds.size.height - strsize.height)/2) withAttributes: dict];
}
@end
将其添加到视图控制器
....
WaterMarkView* view = [[WaterMarkView alloc] init];
view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:view];
....
效果很好。
但是,当屏幕旋转时,会明显看到字符串过渡不流畅,而且很丑。
当我添加一个 UILable whith 字符串时,它会在屏幕旋转时平滑过渡
如何在屏幕旋转时使自定义 UIView 过渡平滑?
【问题讨论】:
标签: ios objective-c uiview screen-rotation uianimation