Я пытаюсь получить одновременное панорамирование из статьи ниже, но я не думаю, что делегат подключен правильно, так как я не вижу никакого эффекта.Прямо сейчас у меня есть панорамирование и распознаватель жестов щипка, которые оба работают.Я делаю IBOutlets для моего viewcontroller, и в моем инициализаторе viewController есть:
EDIT
, вот заголовок и файлы реализации соответственно.
header:
#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
@class GLView;
@interface GLViewController : UIViewController <UIGestureRecognizerDelegate>
@property (strong, nonatomic) IBOutlet UIPinchGestureRecognizer *pinchRecognizer;
@property (strong, nonatomic) IBOutlet UIPanGestureRecognizer *panRecognizer;
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer;
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer;
- (void)drawView:(GLView*)view;
- (void)setupView:(GLView*)view;
@property (retain, nonatomic) IBOutlet UILabel *zoomFactorLabel;
@property (retain, nonatomic) IBOutlet UILabel *xPosLabel;
@property (retain, nonatomic) IBOutlet UILabel *yPosLabel;
@end
panRecognizer.minimumNumberOfTouches = 1;
panRecognizer.delegate = self; // Very important
pinchRecognizer.delegate = self; // Very important
реализация:
#import "GLViewController.h"
#import "GLView.h"
#import "OpenGLCommon.h"
#import "ConstantsAndMacros.h"
#import "TileManager.h"
#import <CoreGraphics/CoreGraphics.h>
@implementation GLViewController
@synthesize pinchRecognizer;
@synthesize panRecognizer;
@synthesize zoomFactorLabel;
@synthesize xPosLabel;
@synthesize yPosLabel;
TileManager* tileManager;
CGPoint currentPosition;
CGPoint start;
CGFloat temp = 0;
CGFloat x=0;
CGFloat y=0;
CGFloat mLastScale=1;
CGFloat mCurrentScale=1;
CGPoint translation;
- (id) init {
self = [super init];
if (self != nil) {
printf("GLViewController initialized.");
tileManager=[[TileManager alloc] init];
currentPosition = CGPointMake(0, 0);
}
return self;
}
CGFloat scale=1;
CGPoint position;
CGPoint mid;
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizershouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSLog(@"delegate called");
// If you have multiple gesture recognizers in this delegate, you can filter them by comparing the gestureRecognizer parameter to your saved objects
return YES; // Also, very important.
}
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer {
scale=scale*recognizer.scale;
mCurrentScale += [recognizer scale] - mLastScale;
mLastScale = [recognizer scale];
if (recognizer.state == UIGestureRecognizerStateBegan)
{
//get midpoint
CGPoint zero=[recognizer locationOfTouch:0 inView:self.view];
CGPoint one=[recognizer locationOfTouch:1 inView:self.view];
float x=zero.x+one.x;
float y=zero.y+one.y;
mid.x=x/2;
mid.y=y/2;
}
else if (recognizer.state == UIGestureRecognizerStateEnded)
{
mLastScale = 1.0;
}
NSString *xPosString = [NSString stringWithFormat:@"%.2f",mid.x];
NSString *yPosString = [NSString stringWithFormat:@"%.2f",mid.y];
xPosLabel.text=xPosString;
yPosLabel.text=yPosString;
}
- (IBAction)handlePan:(UIPanGestureRecognizer* )recognizer {
[recognizer setMaximumNumberOfTouches:1];
translation= [recognizer translationInView:self.view];
NSString *xPosString = [NSString stringWithFormat:@"%.2f",currentPosition.x];
NSString *yPosString = [NSString stringWithFormat:@"%.2f",currentPosition.y];
xPosLabel.text=xPosString;
yPosLabel.text=yPosString;
currentPosition.x=currentPosition.x+translation.x;
currentPosition.y=currentPosition.y+translation.y;
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
- (void)drawView:(GLView*)view
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(mid.x, -mid.y, 0);
glScalef(mCurrentScale,mCurrentScale, 0);
glTranslatef(-mid.x, mid.y, 0);
glTranslatef(currentPosition.x,currentPosition.y*-1,0);
[tileManager drawView:view];
//draw calls
}
-(void)setupView:(GLView*)view
{
CGRect rect = view.bounds;
glViewport(0, 0,rect.size.width,rect.size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0,(rect.size.width),-(rect.size.height),0, -1, 1 ) ;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0,1,1, 1);
// Enable Smooth Shading, default not really needed.
glShadeModel(GL_SMOOTH);
// Depth buffer setup.
glClearDepthf(1.0f);
//enable textures.
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[tileManager setupView:view];
}
- (void)viewDidLoad
{
[super viewDidLoad];
panRecognizer.delegate=self;
pinchRecognizer.delegate=self;
NSLog(@"pan recognizer delegate [%@]", [panRecognizer.delegate description]);
}
- (void)viewDidUnload {
[self setPinchRecognizer:nil];
[self setPanRecognizer:nil];
[super viewDidUnload];
}
@end
NSLog находится в теле метода делегата, но никогда не выполняется.Любая помощь приветствуется.
статья