简体   繁体   English

UIButton不可点击

[英]UIButton is not clickable

I have a function where I move the main view to the side to expose a UIButton . 我有一个函数,可以将主视图移到侧面以显示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. 我已经将self.view.frame更改为一个更大的数字,但是我仍然面临着同样的问题。 I've also tried playing around with insertSubview:aboveSubview: but that also didn't helped. 我也尝试过使用insertSubview:aboveSubview:但这也没有帮助。

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 编辑:我已经上传了我的问题的示例项目https://dl.dropboxusercontent.com/u/137356839/TestMePlz.zip

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 . 所以,你把所有的意见self.view我搬到_containerView Then I obviously added the _containerView to self.view . 然后,我明明添加了_containerViewself.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. 您必须添加QuartzCore和CoreGraphics框架。

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. 谢谢。

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. 我是在您的项目中完成的,并且按钮有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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