【发布时间】:2023-04-03 15:18:01
【问题描述】:
我在 viewController 中有以下代码:
BubbleChatSingleton *myBubble = [BubbleChatSingleton sharedBubbleChat];
UIView *myQuestionView;
myQuestionView = [myBubble createBubbleChat];
[question_middle_view addSubview:myQuestionView];
[myBubble createBubbleChat] 包含以下代码:
UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(18 + (65 * (media_count % 4)), (5 + (media_rows * 65)), 60, 60)];
UIImageView *current_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
// Get the image
documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *imagePath = [NSString stringWithFormat:@"%@/question_image_%@.png", [documentPaths objectAtIndex:0], [current_media objectForKey:@"id"]];
UIImage *mediaImage = [self imageByCropping:[[UIImage alloc] initWithContentsOfFile:imagePath] toRect:CGRectMake(0, 0, 60, 60)];
[current_imageView setImage:mediaImage];
[mediaImage release];
[parentView addSubview:current_imageView];
[current_imageView release];
UIButton *overlay_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
overlay_button.tag = [[current_media objectForKey:@"id"] intValue];
overlay_button.frame = CGRectMake(0, 0, 60, 60);
[overlay_button addTarget:self action:@selector(viewMedia:) forControlEvents:UIControlEventTouchDown];
[parentView addSubview:overlay_button];
但是,overlay_button 没有收到任何点击事件。看起来我根本没有按下按钮。 (即不是我们通常使用 UIButtionTypeRoundedRect 看到的视觉变化)
我已经仔细检查过按钮顶部没有其他视图是透明的,还有其他原因吗?我从单例方法中将按钮作为 UIView 的子视图返回这一事实是否重要?
【问题讨论】:
-
question_middle_view的框架是什么?可能太小了。 -
它根据填充它的内容的高度进行缩放。可悲的是,它工作正常。
标签: iphone objective-c cocoa-touch uibutton singleton