Skip to content

Instantly share code, notes, and snippets.

@nakajijapan
Created July 25, 2012 08:48
Show Gist options
  • Save nakajijapan/3175165 to your computer and use it in GitHub Desktop.
Save nakajijapan/3175165 to your computer and use it in GitHub Desktop.
GestureRecognizerの処理(カメラ拡大時)
//--------------------------------------------------------------------------------
#pragma mark -
#pragma mark GestureRecognizer
//--------------------------------------------------------------------------------
// scale image depending on users pinch gesture
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"-------------------------------");
NSLog(@"%s", __FUNCTION__);
NSLog(@"scale = %f", recognizer.scale);
BOOL allTouchesAreOnThePreviewLayer = YES;
NSUInteger numTouches = [recognizer numberOfTouches];
NSLog(@"touches = %i", numTouches);
NSUInteger i;
for ( i = 0; i < numTouches; ++i ) {
CGPoint location = [recognizer locationOfTouch:i inView:self];
CGPoint convertedLocation = [previewLayer convertPoint:location fromLayer:previewLayer.superlayer];
if ( ! [previewLayer containsPoint:convertedLocation] ) {
NSLog(@"containsPoint!!");
allTouchesAreOnThePreviewLayer = NO;
break;
}
}
if ( allTouchesAreOnThePreviewLayer ) {
NSLog(@"scale in beginGestureScale = %f", beginGestureScale);
effectiveScale = beginGestureScale * recognizer.scale;
NSLog(@"scale in effectiveScale = %f", effectiveScale);
if (effectiveScale < 1.0) {
effectiveScale = 1.0;
}
CGFloat maxScaleAndCropFactor = [[stillImageOutput connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor];
NSLog(@"scale in maxScaleAndCropFactor = %f", maxScaleAndCropFactor);
if (effectiveScale > maxScaleAndCropFactor) {
effectiveScale = maxScaleAndCropFactor;
}
[CATransaction begin];
[CATransaction setAnimationDuration:.025];
[previewLayer setAffineTransform:CGAffineTransformMakeScale(effectiveScale, effectiveScale)];
[CATransaction commit];
}
NSLog(@"effectiveScale = %f", effectiveScale);
NSLog(@"-------------------------------");
}
// ジェスチャー処理がはじまった時の処理
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
NSLog(@"%s", __FUNCTION__);
if ( [gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]] ) {
beginGestureScale = effectiveScale;
}
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment