gpt4 book ai didi

ios - 如何在 Xcode 5 中制作不可见按钮?

转载 作者:行者123 更新时间:2023-11-28 18:34:07 25 4
gpt4 key购买 nike

我正在尝试制作问答游戏。我将 xib View 转换为 ImageView 以放置我预制的问题图像之一。放置图像后,我选择一个按钮并将其放置在图像上。但是,该按钮完全取代了图像。即使将按钮类型设置为自定义后,我也看不到图像。这个想法只是放置四个不可见的按钮,并根据答案进行下一个问题或显示错误的答案图像。感谢您的帮助。

最佳答案

为什么不使用点击手势识别器?

选项 1

第 1 步:将 tapGestureRecognizer 添加到 ImageView

for (UIImageView * v in @[v1, v2, v3, v4]) {
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
}

第 2 步:接收点击

- (void) handleTap:(UITapGestureRecognizer *)tap {
if (tap.view == v1) {
NSLog(@"V1 was tapped");
}
else if (tap.view == v2) {
NSLog(@"V2 was tapped");
}
else if (tap.view == v3) {
NSLog(@"V3 was tapped");
}
else if (tap.view == v4) {
NSLog(@"V4 was tapped");
}
}

选项 2 - Michael Knudsen 的回答

这是迈克尔建议的替代方法

第 1 步:将 tapGestureRecognizer 添加到 ImageView

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
[imageViewsParentView addGestureRecognizer:tap];

第 2 步:接收点击

- (void) handleTap:(UITapGestureRecognizer *)tap {
CGPoint positionInView = [tap locationInView:tap.view];

if (CGRectContainsPoint(v1.frame, positionInView)) {
NSLog(@"V1 was tapped");
}
else if (CGRectContainsPoint(v2.frame, positionInView)) {
NSLog(@"V2 was tapped");
}
else if (CGRectContainsPoint(v3.frame, positionInView)) {
NSLog(@"V3 was tapped");
}
else if (CGRectContainsPoint(v4.frame, positionInView)) {
NSLog(@"V4 was tapped");
}
}

关于ios - 如何在 Xcode 5 中制作不可见按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22256957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com