1

Is there anyway I can get pinch to zoom working for my game when it is running on the iPhone?

I made the game for a class project using Stencylworks. The game runs perfect on the iPad and also works on the iPhone except the scenes are zoomed in which makes it very difficult to play.

Is there any way to implement a pinch gesture that zooms out? Maybe it can be done in Xcode with a view controller or adding code somewhere?? I am new to Xcode so I have absolutely no idea how to get this working!

Not sure if this will help but here are some screen shots of the project.

https://sites.google.com/site/boomblocksgld/pinch-to-zoom

>

#import <Box2D/Box2D.h>
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioServices.h> 
#import "SceneScript.h"

#import "Script.h"

#import "Actor.h"
#import "ActorType.h"
#import "Assets.h"
#import "Behavior.h"
#import "Game.h"
#import "GameModel.h"
#import "GroupDef.h"
#import "FadeInTransition.h"
#import "FadeOutTransition.h"
#import "Region.h"
#import "Runnable.h"
#import "Scene.h"
#import "SHThumbstick.h"
#import "Sparrow.h"
#import "Transition.h"
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKitDefines.h>

@protocol UIGestureRecognizerDelegate;
@class UIView, UIEvent, UITouch;


@interface Design_353_353_PinchZoom : SceneScript 
{
  @public
      NSString* tempHolder;

}
@end

@implementation Design_353_353_PinchZoom


-(void)load
{

}

-(void)update
{  
}
// Gesture Reconizer Methods
-(void)checkpinch {    

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer     >alloc]initWithTarget:self action:@selector(checkpinch)];
[pinch setDelegate:self];
[pinch setDelaysTouchesBegan:YES];
[self.view addGestureRecognizer:pinch];
[pinch release];
}


-(void)render:(SPRenderSupport*)g x:(int)x y:(int)y
{
[super render:g x:x y:y];

}



-(void)forwardMessage:(NSString*)msg
{

}

@end
  • you can use a UIScrollView for this – Felix Apr 15 '12 at 21:45
  • I found a few tutorials about using UIScrollView but I was not able to get it working in my project. Every time I tested a black screen would show up after the loading screen in the simulator. I'm not sure what I'm doing wrong. – user1335118 Apr 15 '12 at 22:02
  • Below is a screenshot of the working Xcode project. – user1335118 Apr 15 '12 at 22:05
  • https://2518569227721903826-a-1802744773732722657-s-sites.googlegroups.com/site/boomblocksgld/pinch-to-zoom/Screen%20Shot%202012-04-15%20at%203.22.10%20PM.png?attachauth=ANoY7crE7dYRjqp8AmU5Wmw5sBgM8XR9A1e3fI_PcOdEvNpUAwFFX9WxlugMJ5U7sQWJFKoQk2L5NNDjttt3PDd2de5vWHKblNuKoSZtz_sc-KPgKi0LTVfdnWYtuWurSdang533I9RFy1ML-4qs3F1okfpI-ul1pl_q1yVA2pb321kGT4S8dvM7IZ0YryRB96itnXuMFGr7CdWnispidOR_kCQg1bqUFf4pmgA8NuunUdhXD1gjMRYbXNPQ0a6NIj7ZaDOENcif&attredirects=0 – user1335118 Apr 15 '12 at 22:05

1 Answers1

1

If you are using iOS 3.2 or later than add following code in you Viewdidload. And add UIGestureRecognizerDelegate in .h file

//Gesture reconizer
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(checkpinch)];
[pinch setDelegate:self];
[pinch setDelaysTouchesBegan:YES];
[self.view addGestureRecognizer:pinch];
[pinch release];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checktap)];
[singleTap setDelegate:self];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired =2;
[self.view addGestureRecognizer:singleTap];
[singleTap release];


UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checktap)];
[doubleTap setDelegate:self];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired =1;
[self.view addGestureRecognizer:doubleTap];
[doubleTap release];


// Gesture Reconizer Methods
-(void)checkpinch {    

    //write here code for your requirements
}

-(void)checktap {

    //write here code for your requirements
}

I hope this will help you...chill

Nitin
  • 7,455
  • 2
  • 32
  • 51
  • I'm using iOS 4.3.2 and I attempted to add the code but I'm still having issues. I made this behavior called PinchZoom in stencylworks and copied your code into a custom code block. Then when I published to Xcode I opened the UIGestureRecognizer.h and copied the #imports, protocol, and class over to my PinchZoom.mm file. I attached the code for the PinchZoom.mm I'm getting 2 errors: Incompatible pointer types sending 'Design_353_353_PinchZoom *' to parameter of type 'id' and Property 'view' not found on object of type 'Design_353_PinchZoom*' – user1335118 Apr 16 '12 at 17:28
  • I think you made mistake to add code...just add this code in your viewdidload directly...and add delegtage in your viewontroller.h file... – Nitin Apr 16 '12 at 17:34
  • I attempted to add the code after, viewdidload, but it was locked.“UIViewController.h” is locked for editing and you may not be able to save your changes. Do you want to unlock it? When I hit unlock, that failed and gave me the following error. Could not add write permission to the parent folder because you do not own it. Try modifying the permissions of the folder in the Finder or Terminal. I changed the permissions in the finder for the files but that did not work. What do you think I should do next??? Thanks – user1335118 May 03 '12 at 18:42