7

Ho una classe chiamata PhotoBoothController che uso per manipolare un'immagine usando gesti. Funziona bene quando lo eseguo su iPhone. Tuttavia, quando lo eseguo su iPad, visualizzo PhotoBoothController all'interno di un UIPopoverController. L'immagine sembra corretta, tuttavia non posso manipolarla poiché i miei gesti non sembrano essere riconosciuti. Non sono sicuro di come UIPopoverController possa assumere il controllo dei gesti.Perdita di ricognitori di gesti in UIPopoverController

presento la popovercontroller e configurare la vista così:

- (void)presentPhotoBoothForPhoto:(UIImage *)photo button:(UIButton *)button { 

    //Create a photoBooth and set its contents 
    PhotoBoothController *photoBoothController = [[PhotoBoothController alloc] init]; 
    photoBoothController.photoImage.image = [button backgroundImageForState:UIControlStateNormal]; 

    //set up all the elements programmatically. 
    photoBoothController.view.backgroundColor = [UIColor whiteColor]; 

    //Add frame (static) 
    UIImage *frame = [[UIImage imageNamed:@"HumptyLine1Frame.png"] adjustForResolution]; 
    UIImageView *frameView = [[UIImageView alloc] initWithImage:frame]; 
    frameView.frame = CGRectMake(50, 50, frame.size.width, frame.size.height); 
    [photoBoothController.view addSubview:frameView]; 

    //Configure image 
    UIImageView *photoView = [[UIImageView alloc] initWithImage:photo]; 
    photoView.frame = CGRectMake(50, 50, photo.size.width, photo.size.height); 
    photoBoothController.photoImage = photoView; 

    //Add canvas 
    UIView *canvas = [[UIView alloc] initWithFrame:frameView.frame]; 
    photoBoothController.canvas = canvas; 
    [canvas addSubview:photoView]; 
    [canvas becomeFirstResponder]; 

    [photoBoothController.view addSubview:canvas]; 
    [photoBoothController.view bringSubviewToFront:frameView]; 

    //resize the popover view shown in the current view to the view's size 
    photoBoothController.contentSizeForViewInPopover = CGSizeMake(frameView.frame.size.width+100, frameView.frame.size.height+400); 

    self.photoBooth = [[UIPopoverController alloc] initWithContentViewController:photoBoothController]; 
    [self.photoBooth presentPopoverFromRect:button.frame 
            inView:self.view 
        permittedArrowDirections:UIPopoverArrowDirectionAny 
            animated:YES]; 
} 

ho pensato [canvas becomeFirstResponder] potrebbe farlo, ma non sembra fare la differenza.

Qualsiasi consiglio molto apprezzato, grazie.

UPDATE: l'aggiunta di codice di cui al commento

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    if (!_marque) { 
    _marque = [CAShapeLayer layer]; 
    _marque.fillColor = [[UIColor clearColor] CGColor]; 
    _marque.strokeColor = [[UIColor grayColor] CGColor]; 
    _marque.lineWidth = 1.0f; 
    _marque.lineJoin = kCALineJoinRound; 
    _marque.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5], nil]; 
    _marque.bounds = CGRectMake(photoImage.frame.origin.x, photoImage.frame.origin.y, 0, 0); 
    _marque.position = CGPointMake(photoImage.frame.origin.x + canvas.frame.origin.x, photoImage.frame.origin.y + canvas.frame.origin.y); 
    } 
    [[self.view layer] addSublayer:_marque]; 

    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)]; 
    [pinchRecognizer setDelegate:self]; 
    [self.view addGestureRecognizer:pinchRecognizer]; 

    UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)]; 
    [rotationRecognizer setDelegate:self]; 
    [self.view addGestureRecognizer:rotationRecognizer]; 

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; 
    [panRecognizer setMinimumNumberOfTouches:1]; 
    [panRecognizer setMaximumNumberOfTouches:1]; 
    [panRecognizer setDelegate:self]; 
    [canvas addGestureRecognizer:panRecognizer]; 

    UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]; 
    [tapProfileImageRecognizer setNumberOfTapsRequired:1]; 
    [tapProfileImageRecognizer setDelegate:self]; 
    [canvas addGestureRecognizer:tapProfileImageRecognizer]; 

} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
    return ![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && ![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]; 
} 
+0

Si prega di aggiungere il codice utilizzato per allegare i rilevatori di gesti al proprio UIPopoverController – Stavash

+0

@stavash terminato - il codice si trova nella classe PhotoBoothController. Grazie! – Smikey

+0

Questo è un problema interessante. Che ne dici di aggiungere i gesti esternamente a UIPopoverController? So che richiede alcuni cambiamenti ma al momento non ho altri suggerimenti ... – Stavash

risposta

1

alcune ipotesi:

  1. è questo perché viewDidLoad metodo sono stati chiamati prima che la proprietà spumanti stata impostata? In questo caso, puoi provare ad aggiungere i riconoscitori dopo il popover presente in un altro metodo come viewDidAppear.

  2. Sono anche d'accordo che la chiave potrebbe essere che UIPopoverController consente l'interazione con altre viste al di fuori del popover. Quindi suggerisco di spostare [canvas becomeFirstResponder]; alla fine del metodo viewDidLoad in PhotoBoothController e provare self.view becomeFirstResponder qui perché in realtà aggiungi i riconoscimenti a self.view.

3

Sto lavorando a un'applicazione simile e posso facilmente manipolare le immagini sulla tela.

1) Verificare che il userInteractionEnabled di proprietà della tela è impostata su YES .
2) È possibile provare ad aggiungere i gesti a ImageView anziché alla tela. (Sto indovinando che vuoi zoomare, ruotare e scorrere le immagini).