Tôi có một UIView mà tôi đã thiết lập để phản ứng với cử chỉ chụm và thay đổi kích thước của nó, ngoại trừ khi bạn phóng to và sau đó thử và véo lại, nó nhảy về kích thước ban đầu (mà chỉ xảy ra là 100x200). Đây là mã:CGAffineTransformMakeScale Làm cho UIView Chuyển sang Kích thước Ban đầu trước khi chia tỷ lệ
@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
Bạn nghĩ gì?
Ngoài ra, autoresizing sẽ gây trở ngại đối với can thiệp vào vị trí, ngay cả khi 'CAAffineTransformScale' được sử dụng. –