当我的游戏在iPhone上运行时,我是否可以轻松缩放工作?
我使用Stencylworks为一个课程项目制作了游戏。该游戏在iPad上运行完美,并且在iPhone上运行,除了场景放大,这使得它很难玩。
有没有办法实现缩小的捏合手势?也许它可以在Xcode中使用视图控制器或在某处添加代码?我是Xcode的新手,所以我完全不知道如何让它工作!
不确定这是否会有所帮助,但这里有一些项目的屏幕截图。
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
答案 0 :(得分:1)
如果您使用的是iOS 3.2或更高版本,请在Viewdidload中添加以下代码。并在.h文件中添加UIGestureRecognizerDelegate
//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
}
我希望这会对你有所帮助......寒意