gpt4 book ai didi

iphone - 如何在负位置的 subview 上点击

转载 作者:行者123 更新时间:2023-11-28 22:37:49 26 4
gpt4 key购买 nike

一天后我放弃了。我找不到解决问题的方法。

我有一张带有自定义标注 View 的 map ,我想检测哪些 View 点击以转到另一个屏幕。

看看我的代码,这是我自定义的 MKAnnotationView

- (void)didAddSubview:(UIView *)subview
{
if ([[[subview class] description] isEqualToString:@"UICalloutView"])
{
for (UIView *subsubView in subview.subviews)
{
if ([subsubView class] == [UIImageView class])
{
UIImageView *imageView = ((UIImageView *)subsubView);
[imageView removeFromSuperview];
}
else if ([subsubView class] == [UILabel class])
{
UILabel *labelView = ((UILabel *)subsubView);
[labelView removeFromSuperview];
}
}
}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

MapAnnotation *ann = self.annotation;

if(selected)
{
calloutView = [[AnnotationCalloutView alloc] initWithFrame:CGRectMake(-40, -50, 200, 30) andAnnotation:ann];

[self addSubview:calloutView];
[self animateCalloutAppearance];
}
else
{
//Remove custom view
[calloutView removeFromSuperview];
[self setCalloutView:nil];
}
}

结果:

Custom Callout

问题就像我必须使用负 Y 位置,标注 View 在注释 View 之外,并且未检测到点击。我尝试了很多解决方案,但没有一个效果很好。

我目前的解决方案是在 pin superview 上直接添加一个带有手势识别器的 View ,效果很好,但如果用户缩放我的 View ,我的 View 就会消失。

请帮助我,否则我会自杀;)

编辑:我仍然没有找到解决方案,但现在当我捏合 map 进行缩放时,我在 pin superview 上的 View 不再消失(我添加了一个手势识别器来拦截捏合事件)。所以它可以是一个解决方案,但绝对不是一个好的解决方案。

编辑 2:在我的自定义注释 View 上覆盖 hitTest 是解决方案。我现在可以检测到点击我的标注 subview 。

最佳答案

尝试覆盖 -hitTest:withEvent:

关于iphone - 如何在负位置的 subview 上点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15399402/

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