7

Tôi có một lớp được gọi là PhotoBoothController mà tôi sử dụng để thao tác hình ảnh bằng cử chỉ. Nó hoạt động tốt khi tôi chạy nó trên iPhone. Tuy nhiên khi tôi chạy nó trên iPad, tôi hiển thị PhotoBoothController bên trong một UIPopoverController. Hình ảnh có vẻ tốt, tuy nhiên tôi không thể thao tác nó vì cử chỉ của tôi dường như không được công nhận. Tôi không chắc chắn làm thế nào để làm cho UIPopoverController kiểm soát các cử chỉ.Mất nhận dạng cử chỉ trong UIPopoverController

tôi trình bày các popovercontroller và cấu hình quan điểm như sau:

- (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]; 
} 

Tôi nghĩ [canvas becomeFirstResponder] có thể làm điều đó nhưng nó không xuất hiện để tạo sự khác biệt.

Bất kỳ lời khuyên nào đánh giá cao, cảm ơn bạn.

UPDATE: thêm mã theo bình luận

- (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

Vui lòng thêm mã được sử dụng để đính kèm (các) trình nhận dạng cử chỉ vào UIPopoverController – Stavash

+0

@stavash của bạn - mã nằm trong lớp PhotoBoothController. Cảm ơn! – Smikey

+0

Đây là một vấn đề thú vị. Làm thế nào về việc thêm các cử chỉ bên ngoài vào UIPopoverController? Tôi biết nó đòi hỏi khá nhiều thay đổi nhưng tôi không có bất kỳ đề xuất nào khác ngay bây giờ ... – Stavash

Trả lời

1

một số dự đoán:

  1. là này vì viewDidLoad phương pháp đã được gọi trước khi sở hữu Cavas được thiết lập? Trong trường hợp này, bạn có thể thử thêm các trình nhận dạng sau popover hiện tại theo một phương thức khác chẳng hạn như viewDidAppear.

  2. Tôi cũng đồng ý rằng khóa có thể là UIPopoverController cho phép tương tác với các chế độ xem khác bên ngoài cửa sổ bật lên. Vì vậy, tôi đề nghị di chuyển [canvas becomeFirstResponder]; đến cuối phương pháp viewDidLoad trong PhotoBoothController và thử self.view becomeFirstResponder tại đây vì bạn thực sự thêm trình nhận dạng vào self.view.

3

Tôi đang làm việc trên một ứng dụng tương tự và tôi có thể dễ dàng thao tác hình ảnh trên canvas.

1) Kiểm tra xem thuộc tính userInteractionEnabled của canvas được đặt thành YES.
2) Bạn có thể thử thêm các cử chỉ vào ImageView thay vì canvas. (Tôi đoán bạn muốn thu phóng, xoay n vuốt hình ảnh).

Các vấn đề liên quan