开发者

UIScrollview contents always on top

开发者 https://www.devze.com 2023-04-12 02:04 出处:网络
I am trying to make my UIScrollView take up all the screen and have an image inside of it which the user can zoom, pan, etc. This all works. But, when then user taps the screen once, I want that on to

I am trying to make my UIScrollView take up all the screen and have an image inside of it which the user can zoom, pan, etc. This all works. But, when then user taps the screen once, I want that on top of this UIScrollView an additional view appears with some information about the picture. The problem is that no matter what I do, the UIScrollView's child ImageView is always on top. I have tried changing the order of the views in the xib, I have tried using bringSubViewToFront with no success. Here is the code:

- (void)viewDidLoad {       
    [super viewDidLoad];
    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(flipViewSingleTap:)];  
    singleTapGesture.delegate = self;    

    self.flippedImage.userInteractionEnabled = YES;
    [self.flippedImage addGestureRecognizer:singleTapGesture];

    [singleTapGesture release];

    self.flippedImageView.contentSize = CGSizeMake(1024, 768);
    self.flippedImageView.delegate = self;

    self.flippedMenuView.alpha = 0.0f开发者_如何学JAVA;
}

- (IBAction)flipViewSingleTap:(UIGestureRecognizer *)sender {
    flipItemsVisible = !flipItemsVisible;
    [self.view bringSubviewToFront:self.flippedMenuView];
    [UIView animateWithDuration:0.5f 
                          delay:0.0f 
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         self.flippedMenuView.alpha = flipItemsVisible ? 1.0f : 0.0f
              } 
                     completion:nil];
}


Maybe add this line to viewDidLoad:

[self.view addSubview:self.flippedMenuView];

(This assumes that self.view is the UIScrollView.)


Try to add a gestureRecognizer:shouldReceiveTouch: delegate method that ignores the menu view.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
       shouldReceiveTouch:(UITouch *)touch {
  return ![touch.view isDescendantOfView:self.flippedMenuView];
}


Turning on userInteraction for the image view isn't enough. Its default method for touchesMoved/Began are blank ( I think).

Make sure your own custom subclass of UIImageView is what the flippedImageView is. Overwrite those methods and send a delegate message (custom) that says something like "userTappedImageAt:".

If your subview handling just won't bring anything to the front, and your touches are working, grab the application delegate window [[[UIApplication sharedApplication] delegate] window] and add a subview to it, however it's probably safer to use a view so you can use convertPoint: from/to functions.

Most of what I told you can be inferred from reading the Views and Programming Guide, along with questions on SO with answers as to getting views on top.

You can always "roll your own" subviews to avoid unknown SDK recognizers.

Good luck, Stephen

0

精彩评论

暂无评论...
验证码 换一张
取 消