jps*_*jps 12 cocoa-touch objective-c ipad ios4
我有一个UIView,我设置为响应捏手势并改变它的大小,除了,一旦你放大它然后尝试再次捏它,它跳到它的原始大小(恰好是100x200).这是代码:
@implementation ChartAxisView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// do gesture recognizers
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinch:)];
[self addGestureRecognizer:pinch];
[pinch release];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0].CGColor;
CGContextSetFillColorWithColor(context, redColor);
CGContextFillRect(context, self.bounds);
}
- (void)onPinch: (UIPinchGestureRecognizer*) gesture {
self.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale);
}
- (void)dealloc {
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
Mih*_*ria 27
因此有两种类型的Scale(或一般转换)函数:CGAffineTransformMakeScale和CGAffineTransformScale
CGAffineTransformMakeScale
您正在使用的第一个,始终根据图像的原始大小进行转换.这就是为什么你看到在缩放发生之前跳转到原始大小的原因.
第二个,CGAffineTransformScale
从图像的当前位置转换.这就是你需要的.为此,它需要一个额外的'转换'arg.在您的情况下,'变换'arg代表放大的图像.
阅读这篇关于转换的非常翔实的博客文章.
归档时间: |
|
查看次数: |
21540 次 |
最近记录: |