【发布时间】:2012-07-02 05:25:05
【问题描述】:
视图都有一个框架(超级视图坐标系中的坐标) 和 bounds (在自己的坐标系中的坐标)属性,但如果你 转换视图,不应使用或依赖 frame 属性 了。如果您正在使用转换,请使用边界 仅属性,而不是框架属性,因为应用了转换 到界限,但不一定准确反映在帧中
http://iphonedevelopment.blogspot.jp/2008/10/demystifying-cgaffinetransform.html
我想看看他在上一段中的意思并打印了“框架”和“边界”
而且我看到只有“框架”在紧要关头发生了变化。
- (IBAction)handlePinch:(UIPinchGestureRecognizer*)recognizer
{
NSLog(@"scale: %f, velocity: %f", recognizer.scale, recognizer.velocity);
NSLog(@"Before, frame: %@, bounds: %@", NSStringFromCGRect(recognizer.view.frame), NSStringFromCGRect(recognizer.view.bounds));
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
NSLog(@"After, frame: %@, bounds: %@", NSStringFromCGRect(recognizer.view.frame), NSStringFromCGRect(recognizer.view.bounds));
recognizer.scale = 1;
}
输出:(放大)
2012-07-02 14:53:51.458 GestureRec[1264:707] scale: 1.030111, velocity: 0.945660
2012-07-02 14:53:51.466 GestureRec[1264:707] Before, frame: {{0, 124}, {320, 160}}, bounds: {{0, 0}, {320, 160}}
2012-07-02 14:53:51.473 GestureRec[1264:707] After, frame: {{-4.81771, 121.591}, {329.635, 164.818}}, bounds: {{0, 0}, {320, 160}}
2012-07-02 14:53:51.480 GestureRec[1264:707] scale: 1.074539, velocity: 1.889658
2012-07-02 14:53:51.484 GestureRec[1264:707] Before, frame: {{-4.81771, 121.591}, {329.635, 164.818}}, bounds: {{0, 0}, {320, 160}}
2012-07-02 14:53:51.494 GestureRec[1264:707] After, frame: {{-17.103, 115.449}, {354.206, 177.103}}, bounds: {{0, 0}, {320, 160}}
2012-07-02 14:53:51.499 GestureRec[1264:707] scale: 1.000000, velocity: 1.889658
2012-07-02 14:53:51.506 GestureRec[1264:707] Before, frame: {{-17.103, 115.449}, {354.206, 177.103}}, bounds: {{0, 0}, {320, 160}}
2012-07-02 14:53:51.510 GestureRec[1264:707] After, frame: {{-17.103, 115.449}, {354.206, 177.103}}, bounds: {{0, 0}, {320, 160}}
是我理解有误还是博主有误?
【问题讨论】:
-
您能否记录转换前后的值,并记录您正在使用的比例值?实际上在你的问题中包含输出:)
标签: ios frame cgaffinetransform bounds