简体   繁体   中英

Hide a UIbutton when another UIbutton is pressed

I have a record button, which when pressed, I want to hide the instructions button.

Here's the code for the record button:

// Create custom overlay
// Create instruction/record button
// Add instruction/record button to custom overlay
[_videoRecordBtn addTarget:self action:@selector(startVideoRecord:) forControlEvents:UIControlEventTouchUpInside];

So in startVideoRecord I should have something like:

-(IBAction)startVideoRecord:(id)sender{
    [_instru setHidden:YES];
    // start recording...
}

But I have no idea how to pass the _instru button over to startVideoRecord .

You can do this by 2 way..

1 way - > you set the tag of instructions button .

and use this

-(IBAction)startVideoRecord:(id)sender{

UIButton *instruBtn = (UIButton*)[self.view viewWithTag:your button tag];


instruBtn.hidden = YES;

// start recording...
}

2nd Way - > you make property for your instructions button and use like this

  -(IBAction)startVideoRecord:(id)sender{

    self.instruBtn.hidden = YES;

    // start recording...
    }

Add a property to your ViewController to keep a reference to your instructionsButton:

@property (nonatomic, strong) UIButton *instructionsButton;

When you create your instructionsButton, assign it to this property.

Then you can access the button via this property anywhere in your ViewController with self. instructionsButton self. instructionsButton .

So, your action method would be like:

-(IBAction)startVideoRecord:(id)sender{
    self.instructionsButton.hidden = YES;
    // start recording...
}

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