UIVut里面的UIButton不可点击

wou*_*_be 5 iphone uibutton uiviewcontroller ios

我有点卡在这个,我有一个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];
Run Code Online (Sandbox Code Playgroud)

为了看看是否有任何重叠,我添加了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
Run Code Online (Sandbox Code Playgroud)

DownloadButton只是一个简单的UIButton,没什么特别的.

Nit*_*hin 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);
Run Code Online (Sandbox Code Playgroud)

如果你的按钮的框架在其父视图的框架之外(viewcontroller的视图),上面提到的框架,它将不会响应你的触摸