【问题标题】:-(void)touchesBegan (TO A SPECIFIED UIIMAGEVIEW)-(void)touchesBegan (到指定的 UIIMAGEVIEW)
【发布时间】:2011-05-28 09:19:54
【问题描述】:

您好,我想这样做,如果您触摸我放在视图上的图像,就会发生 -(void)checkcollision。 -(void)checkcollision 发生了,但是当我触摸任何东西时。我怎么能说它只有在我触摸指定的图像时才有效。例如一个疙瘩:

IBOutlet UIImageView *pimple;
@property (nonatomic, retain) UIImageView *pimple;

这里是 touchesBegan 代码

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


    UITouch *myTouch = [[event allTouches] anyObject];
    [self checkcollision];
}


-(void)checkcollision {

    if (label.text = @"0") {
        label.text = @"1";
    }

    pimple.hidden = YES;
}

【问题讨论】:

    标签: objective-c touchesbegan


    【解决方案1】:
    CGPoint point = [myTouch locationInView:pimple];
    if ( CGRectContainsPoint(pimple.bounds, point) ) {
        ... Touch detected.
    }
    

    您也可以考虑gesture recognizers。在这种情况下,您可以使用点击识别器。

    【讨论】:

    • 我把这个代码: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [touches anyObject]; CGPoint 点 = [myTouch locationInView:pimple]; if ( CGRectContainsCGPoint(pimple.bounds, point) ) { [self checkcollision];我得到这个警告:函数'CGRectContainsCGPoint'的隐式声明并得到这个错误:
    • 这个错误:“_CGRectContainsCGPoint”,引用自:GameScreen.o ld 中的 -[GameScreen touchesBegan:withEvent:]:未找到符号 collect2:ld 返回 1 个退出状态
    【解决方案2】:

    有两种选择:

    1. 继承 UIImageView 并定义您自己的处理程序
    2. 检查发件人- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 并将其与您的UIImageView 实例进行比较。

    【讨论】:

    • ???更多帮助......我有点新,在这种情况下,我坚持你的解释。你能写代码然后指出它的含义吗
    • 如果我有一个 UIImageView 的子类,我将不得不正确地导入图像。这不会需要更长的时间吗?
    • UIImageView 并不意味着被子类化。苹果的推荐。
    • 好吧。行。但是请提供一些帮助
    猜你喜欢
    • 2010-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2019-09-27
    • 2012-05-06
    • 2011-08-28
    • 1970-01-01
    相关资源
    最近更新 更多