1)我正在对UIImageView进行缩放缩放,我应该如何决定zoomfactor值,因为当zoomfactor值超过0 [即负值]时,图像会被倾斜,我不希望它发生。如何避免这种情况。
2)Y是旋转发生的旋转,Y不是平滑的旋转?这将被照顾
CGAffineTransformMakeScale(zoomfactor,zoomfactor);
的方法?
这就是我在我的代码中所做的: zoomFactor = 0; //最初缩放因子设置为零
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@" Inside touchesBegan ..................");
NSArray *twoTouches = [touches allObjects];
UITouch *first = [twoTouches objectAtIndex:0];
OPERATION = [self identifyOperation:touches :first];
NSLog(@"OPERATION : %d",OPERATION);
if(OPERATION == OPERATION_PINCH){
//double touch pinch
UITouch *second = [twoTouches objectAtIndex:1];
f_G_initialDistance = distanceBetweenPoints([first locationInView:self.view],[second locationInView:self.view]);
}
NSLog(@" leaving touchesBegan ..................");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@" Inside touchesMoved .................");
NSArray *twoTouchPoints = [touches allObjects];
if(OPERATION == OPERATION_PINCH){
CGFloat currentDistance = distanceBetweenPoints([[twoTouchPoints objectAtIndex:0] locationInView:self.view],[[twoTouchPoints objectAtIndex:1] locationInView:self.view]);
int pinchOperation = [self identifyPinchOperation:f_G_initialDistance :currentDistance];
G_zoomFactor = [self calculateZoomFactor:pinchOperation :G_zoomFactor];
[uiImageView_G_obj setTransform:CGAffineTransformMakeScale(G_zoomFactor, G_zoomFactor)];
[self.view bringSubviewToFront:resetButton];
[self.view bringSubviewToFront:uiSlider_G_obj];
f_G_initialDistance = currentDistance;
}
NSLog(@" leaving touchesMoved ..................");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@" Inside touchesEnded ..................");
NSArray *twoTouches = [touches allObjects];
UITouch *first = [twoTouches objectAtIndex:0];
if(OPERATION == OPERATION_PINCH){
//do nothing
}
NSLog(@" Leaving touchesEnded ..................");
}
谢谢。
答案 0 :(得分:0)
如果您能够将应用程序限制为OS 3.2或更高版本(或者如果它是仅限iPad的应用程序),建议您查看UIPinchGestureRecognizer
和UIGestureRecognizer
类。他们带走了很多痛苦。您可以获取它们返回的比例或旋转值,并将它们直接输入CGAffineTransform
创建函数。