开发者

How To disable the userinteraction of a view except one object?

In My view there is reset button .i need userinteraction disabled except for that button .how 开发者_StackOverflow社区can i do that can any one share the code.thanks in advance?


btn1 is your button, self.view - your view

for (UIView *view in self.view.subviews)
    view.userInteractionEnabled=NO;
btn1.userInteractionEnabled=YES;


For all the elements there is a property userinteractionenabled. Set it to false

yourelement.userInteractionEnabled = NO;

Also place your UIButton on top of your view hierachy.

Other option is to place a tranparent UIButton on your entire view and your UIButton on top of this view. This way only your UIButton is touch enalbed. Other touches would be taken in by the transparent button which does nothing.


Sligthly better approach, define a "magic value" that will help you :

#define kDontDisableUserInteraction 3928473

then set this value as the tag of your button you don't want disabled:

[resetButton setTag:kDontDisableUserInteraction];

you can now create a function in your superview's class :

- (void)setInterfaceEnabled:(BOOL)newEnabled {
    for (UIView *subview in self.subviews) {
        if (subView.tag != kDontDisableUserInteraction)
            continue;
        subView.userInteractionEnabled = newEnabled;
    }
}

That allows you to create other non-disableable buttons simply by giving them the right tag (which can be whatever int value you want, not only 3928473, depends on your #define).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜