简体   繁体   中英

Custom UIButton that generates UIView in SuperView

I'm experimenting a custom class button that display the UIView when touch start. I have a UIButton class name it TapInButton. here're codes.

#import "TapInButton.h"
#import "TapInViewController.h"

@interface TapInButton()
@property (nonatomic,strong) TapInViewController * tapIn;
@end
@implementation TapInButton
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    self.tapIn = [[TapInViewController alloc] initWithNibName:@"TapIn" bundle:nil];
    self.tapIn.view.frame = CGRectMake(0, 50, 300, 500);
    self.tapIn.view.backgroundColor = [UIColor redColor];

    [self.superview addSubview:self.tapIn.view];


}

As you can see, I import TapInViewController that generates xib file. When the user click the tapin button that has a custom class TapInButton. It Display the xib file. see image below 在此处输入图片说明

I successfully add the xib to the main ViewController but the problem is I cannot click the button inside the xib file. Is there something missing in my code? or Is this possible to generate a uiview inside a custom UIButton?

I know the other way to generate a xib file but not using custom button. I just want to clarify my mind if this is possible. Hoping for your advice or explanation. Thanks in advance

the problem is I connot click the button inside the xib file. Is there something missing in my code?

You'll have to obtain a reference to the button in code and set up the button-click action connection in code (by calling addTarget:action:forControlEvents: ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM