我有点卡在这一个上,UIButton
内有UIViewController
,但由于某种原因,UIButton
没有响应。
_downloadButton = [[DownloadButtonViewController alloc] init];
_downloadButton.issue = _issue;
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);
[self.view addSubview:_downloadButton.view];
UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmpButton.titleLabel.text = @"test";
tmpButton.frame = CGRectMake(_downloadButton.view.frame.origin.x, _downloadButton.view.frame.origin.y - 30, _downloadButton.view.frame.size.width, _downloadButton.view.frame.size.height);
[self.view addSubview:tmpButton];
要查看是否有任何重叠,我添加了另一个UIButton
稍微低一点,即使我将它添加到相同位置仍然有效。
我的应用程序的结构是这样的
- UIViewController
- UIScrollView
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
- ThumbCover
- UIImageView
- DownloadButton --> NOT WORKING
- UIButton --> WORKING
- UILabel
DownloadButton
只是一个简单的UIButton
,没什么特别的。
答案 0 :(得分:15)
您已将viewcontroller视图的高度指定为27
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);
如果你的按钮的框架在其父视图的框架之外(viewcontroller的视图),上面提到的框架,它将不会响应你的触摸
答案 1 :(得分:0)
你真的为按钮设定了一些目标吗? (在提供的代码中询问,我看不到它!)否则,它当然不会响应。
答案 2 :(得分:0)
我把你的代码改成了两行覆盖,所以试试这段代码......
_downloadButton = [[DownloadButtonViewController alloc] init];
_downloadButton.issue = _issue;
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);
UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmpButton.titleLabel.text = @"test";
tmpButton.frame = CGRectMake(_downloadButton.view.frame.origin.x, _downloadButton.view.frame.origin.y - 30, _downloadButton.view.frame.size.width, _downloadButton.view.frame.size.height);
[self.view addSubview:tmpButton];
[self.view addSubview:_downloadButton.view];
希望这能帮到你......
:)
答案 3 :(得分:0)
就我而言,似乎我的动画过渡尚未完成。我忘了将completeTransition:Bool
放在animateTransition:context
方法的末尾,因此我的视图控制器中的所有按钮都被禁用,而不是userinteractionEnabled
。
答案 4 :(得分:-2)
看着你这段代码
_downloadButton = [[DownloadButtonViewController alloc] init];
不是说我的意思是你的命名方式错了,但我怀疑你的DownloadButtonViewController是否是UIButton。只是为了确保打开你的 DownloadButtonViewController.h 并检查你是否有这个
@interface DownloadButtonViewController : UIButton
答案 5 :(得分:-3)
replace this line..
tmpButton.titleLabel.text = @"test";
作为
[tmpButton setTitle: @"test" forState:UIControlStateNormal];