1

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

Segev
  • 19,035
  • 12
  • 80
  • 152

3 Answers3

2

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.

Mikael
  • 3,572
  • 1
  • 30
  • 43
  • Yes, didn't you get the link? Here it is: https://dl.dropboxusercontent.com/u/768979/TestMePlz.zip – Mikael Jul 01 '13 at 11:12
  • The problem is that if for example I'll drag a UISlider or a button to the ViewController in the interface builder, when clicking on the rightMenuButton I will see the menu but the main viewController won't move to the left. So, it shows me the right menu but doesn't move the current ViewController to the side. – Segev Jul 01 '13 at 11:33
  • But if you remove all references to _containerView and change it to self.view (as you had before) you can add stuff in IB and it will be moved with it. – Mikael Jul 01 '13 at 11:39
  • You're right. The current ViewController will move But then the button in the right menu is not clickable again.. back to square one. – Segev Jul 01 '13 at 11:47
  • Don't have much time to spend on this right now. But have a look at http://stackoverflow.com/questions/5432995/interaction-beyond-bounds-of-uiview . Seems to solve the issue. – Mikael Jul 01 '13 at 12:28
  • Looks like the right solution but for some reason `pointInside:withEvent` is not getting called. I'd love to see how you implement this when you'll have more time. Thanks – Segev Jul 01 '13 at 14:02
0

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.

sagarcool89
  • 1,366
  • 8
  • 16
  • @Sha you are not able to click on the half part of UIButton due to testview frame. its start from 300.0 and ands at 320.0. – sagarcool89 Jul 01 '13 at 10:39
  • How can I fix this? I tried editing the testView frame without success. I've uploaded a sample project to my question. – Segev Jul 01 '13 at 10:46
0

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.

Leta0n
  • 571
  • 2
  • 8