Reputation: 19303
I have a function where I move the main view to the side to expose a UIButton
. The part of the button that's inside the view is clickable but the right side of the button is not.
I've changed the self.view.frame to a much bigger number but I'm still facing the same problem. I've also tried playing around with insertSubview:aboveSubview:
but that also didn't helped.
self.view.frame = CGRectMake(0, 0, 1600, 568);
_testView = [[UIView alloc]initWithFrame:CGRectMake(300, 20, 120, 100)];
_testView.backgroundColor = [UIColor greenColor];
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame = CGRectMake(0, 0, 120, 100);
[test addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
[_testView addSubview:test];
[self.view addSubview:_testView];
- (void)showRightMenu
{
CGRect frame = self.view.frame;
frame.origin.x = -100;
self.view.frame = frame
}
Edit: I've uploaded a sample project of my problem https://dl.dropboxusercontent.com/u/137356839/TestMePlz.zip
Upvotes: 1
Views: 3093
Reputation: 571
Try this:
[test addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
And then change your method:
-(void)doSomething:(id)sender
{
NSLog(@"Bug Fixes:!!!!!!!");
}
I did it in your project and button works.
Upvotes: 0
Reputation: 3612
After you sent me your code I changed some things:
First I created a container view (makes it easier to track all the views):
_contatinerView = [[UIView alloc] initWithFrame:self.view.frame];
So all the views you put in self.view
I moved to _containerView
. Then I obviously added the _containerView
to self.view
.
Instead of using:
CGRect frame = self.view.frame;
frame.origin.x = -100;
self.view.frame = frame;
I did:
[_contatinerView setTransform:CGAffineTransformTranslate(_contatinerView.transform,-100, 0)];
You'll have to add the QuartzCore and CoreGraphics frameworks.
Upvotes: 2
Reputation: 1376
Please correct position of your View :
self.view.frame = CGRectMake(0, 0, 320, 568);
_testView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 320, 100)];
_testView.backgroundColor = [UIColor greenColor];
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame = CGRectMake(0, 0, 120, 100);
[test addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
[_testView addSubview:test];
[self.view addSubview:_testView];
Thanks.
Upvotes: 0