开发者

How to make buttons unclickable behind a small UIView?

开发者 https://www.devze.com 2023-04-09 11:59 出处:网络
I have a strange problem.I have 3 level of views : - MainView - containerview - subview -some buttons -some buttons

I have a strange problem. I have 3 level of views :

- MainView
    - containerview
        - subview
            -some buttons
    -some buttons

I've made a animation to make my subview appears and disappear by clicking a button in the master view. The following is a part of the code to make the subview disappeared and reappeared :

 [UIView animateWithDuration:0.4 //begin animation
                      delay:0.1 
                    options:UIViewAnimationCurveEaseIn 
                 animations:^{
                     [UIView transitionWithView:containerview 
                                       duration:0.4
                                        options:UIViewAnimationOptionTransitionCurlUp
                                     animations:^{ [subView removeFromSuperview] ;}
                          开发者_如何学Go           completion:nil];
                     containerview.alpha = 0;

                 } 
                 completion:^(BOOL finished){
                     saveButton.hidden = true;
                     saveDAVButton.hidden = true;    
                     saveDBButton.hidden = true; 
                     loadButton.hidden = false;
                     openDAVButton.hidden = false;    
                     openDBButton.hidden = false;
                     [UIView transitionWithView:containerview 
                                       duration:0.4
                                        options:UIViewAnimationOptionTransitionCurlDown
                                     animations:^{ [containerview addSubview:subView] ;}
                                     completion:nil];
                     containerview.alpha = 1;
                 }
 ];

This animation works perfectly. The only problem is that even when the subview is visible (so subview buttons as well), i can click buttons behind the subview! (buttons from the master view). That makes buttons from the subview hard to use, because they overlap buttons from masterview.

Any idea how to make element behind the subview unclickable?

I already tried to make buttons from master view disable and hidden, but even then, i can't use overlapping buttons from subview!

Thank you for your help.

UPDATE I've found what the problem is. Actually, i have again to make my post clearer. Here is the hierarchy of the views, with there position and size :

- MainWindow (0,0,768,1024)
    - MainView (0,0,768,80) (this is actually a top tool bar)
        - containerview (500,40,120,80)
            - subview (500,40,120,80) (will act as a post it : curl up and down...)

So, the problem is that the bottom of my subview is going outside of MainView. Nothing happen when a click to buttons place at the bottom of subview. In fact, i am clicking on MainWindow! Hafl of subview is unclickable...

Before changing all my code, is there a way to make accessible bottom of subview even if he is part of MainView? Or do i have to move it in MainWindow?

Thank you again...


Switch the view's userInteractionEnabled property.


Possibly the problem is that your buttons from the master view are in front of the containerView. Try:

[MainView bringSubviewToFront:containerView];

Or in interface builder rearrange the order of containerView and the buttons that are in the main view.

But I don't know, setting the buttons to hidden should make them hidden and unclickable, and prevent them from blocking touches to views behind them.


Seeing your latest edit, perhaps you could check your clipsToBounds property (though getting everything to work right when things are outside a parent's bounds can be tricky — I can’t recall now but I may have given up and changed my containment hierarchy).

0

精彩评论

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

关注公众号