所以我已经子类化UIView并添加了一些绘图代码。我正在缩放产生的视图。 我想这个观点是独立的分辨率,使其在任何规模的清晰,我不会需要管理多个图像等等,等等UIView中矢量图形的平滑缩放
作为一个测试,我做了一下绘图代码看起来的喜欢这个。 它创建适合UIView的任何帧大小的同心椭圆。 实际上,外圈比框架稍小,因此不会被剪切。对此很好。实际的图形将更加复杂,并且将包含必须以小尺寸和具有这种性质的东西可读的文本。
- (void)drawRect:(CGRect)rect
{
UIColor* color = [UIColor colorWithRed: 0.833 green: 0.833 blue: 0.833 alpha: 1];
float width = self.bounds.size.width;
float height = self.bounds.size.height;
float scalePercent = 0.8;
for(int i = 0; i < 10; i++){
width = width * scalePercent;
height = height * scalePercent;
float x = (self.bounds.size.width - width)/2;
float y = (self.bounds.size.height - height)/2;
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(x, y, width, height)];
[color setStroke];
ovalPath.lineWidth = 2;
[ovalPath stroke];
}
}
现在,这里的换算:
- (void) makeBig{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
self.transform = CGAffineTransformMakeScale(2, 2);
}
completion:^(BOOL finished){
}];
}
当你运行这个视图缩放,但它是像素化。这是像素化的,因为视图尺寸增加了一倍,但分辨率没有改变。
所以,这里是如何不这样做。
- (void) makeBig{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
self.transform = CGAffineTransformMakeScale(2, 2);
}
completion:^(BOOL finished){
CGRect targetFrame = self.frame;
self.transform = CGAffineTransformIdentity;
self.frame = targetFrame;
[self setNeedsDisplay];
}];
}
这可以工作,但修复程序在动画结束时可以在分辨率捕捉回屏幕分辨率时看到。 我可以尝试预先缩放视图并预先绘制最终大小,然后将其缩小,然后运行动画以再次缩放它,但出于各种原因,我可以认为这听起来完全愚蠢。我想我可能是错的,这是自火灾以来最明智的想法。但我有点怀疑。
那么矢量内容的平滑度如何做得最好呢?
你好,我也试图画一个可缩放的向量,请帮助http://stackoverflow.com/questions/38191771/draw-zoomable-vector-in-ios-using-coregraphics – anoop4real 2016-08-01 12:53:45