简体   繁体   English

UIVut里面的UIButton不可点击

[英]UIButton inside UIView not clickable

I'm a little stuck on this one, I have a UIButton inside a UIViewController , but for some reason the UIButton is not responding. 我有点卡在这个上,我在UIViewController有一个UIButton ,但由于某种原因, 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];

To see if nothing was overlapping it, I added another UIButton a little lower, even if I add it on the same position it still works. 为了查看是否有任何重叠,我添加了另一个UIButton稍低,即使我将它添加到它仍然有效的相同位置。

The structure of my application is like this 我的应用程序的结构是这样的

- 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

The DownloadButton is just a simple UIButton , nothing special at all. DownloadButton只是一个简单的UIButton ,没什么特别的。

You have specified the height of the viewcontroller's view as 27 您已将viewcontroller视图的高度指定为27

_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);

If your button's frame is outside the frame of its parent view (viewcontroller's view), the abovesaid frame, it wouldn't respond to your touches 如果你的按钮的框架在其父视图的框架之外(viewcontroller的视图),上面提到的框架,它将不会响应你的触摸

Did you actually set some target for the button? 你真的为按钮设定了一些目标吗? (Asking since in the provided code, I cannot see that!) Otherwise, it would not response at all of course. (在提供的代码中询问,我看不到!)否则,它根本不会响应。

i put your code but change two line which overrite so just try this code... 我把你的代码但更改了两行覆盖,所以只需尝试此代码...

_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];

hope this help you... 希望这能帮到你......

:) :)

In my case, it seems like my animated transitioning is not yet completed. 就我而言,似乎我的动画过渡还没有完成。 I forgot to to put completeTransition:Bool at the end of my animateTransition:context method making all the buttons inside my view controller disabled and not userinteractionEnabled . 我忘了在我的animateTransition:context方法的末尾放置completeTransition:Bool ,使我的视图控制器中的所有按钮都被禁用,而不是userinteractionEnabled

Looking at you this code 看着你这段代码

_downloadButton = [[DownloadButtonViewController alloc] init];

Not that i mean your naming way is wrong but I doubt if your DownloadButtonViewController is UIButton or not. 不是说我的意思是你的命名方式错了,但我怀疑你的DownloadButtonViewController是否是UIButton。 Just to make sure open your DownloadButtonViewController.h and check if you have got this or not 只是为了确保打开你的DownloadButtonViewController.h并检查你是否有这个

@interface DownloadButtonViewController : UIButton
replace this line.. 

tmpButton.titleLabel.text = @"test";

as

[tmpButton setTitle: @"test" forState:UIControlStateNormal];

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

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