UIView alpha = 0 causes touches to be dropped to the view below

后端 未结 2 436
半阙折子戏
半阙折子戏 2021-01-04 18:32

So I created a glass pane or a custom UIView to handle touches. This glass pane sits on top of other views such as dummy UIButtons. When I set the alpha to be 0, the touches

2条回答
  •  孤城傲影
    2021-01-04 18:54

    Yes, alpha=0.0f; and hidden=YES; have the same effect. This is very useful, because you can animate a fade-out and not have to worry about touches on the invisible object - ie you can say:

    -(void)hideOverlayButton
    {
        [UIView beginAnimations:@"hideOverlayButton" context:nil];
        [UIView setAnimationDuration:0.2];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [self.overlayButton setAlpha:0.0];
        [UIVIew commitAnimations];
    }
    

    Then, when the animation is complete, the button won't respond to touches - there's no need to worry about deactivating it.

    If what you want is to have invisible buttons, put a UIButton on the view, make sure it's at the front (bottom of the list in interface builder), set it's type to custom; don't set an image, background image or title. By default in interface builder you'll get alpha of 1 and a clear color.Then you can wire-up the IBOutlets in the usual way.

提交回复
热议问题