0

iPad用のiOSアプリを開発しています。I コードを使用して、ユーザーがオブジェクトに触れたときを検出しますが、同じコードを使用して、ユーザーがオブジェクトに触れていないときを検出したいと考えています。これはコードです:

  - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];

if (CGRectContainsPoint(ribbon.frame, location) || CGRectContainsPoint(inferior.frame, location) || CGRectContainsPoint(superior.frame, location) & (pujat==YES)){
    pujat=NO;
    [UIView animateWithDuration:0.25 animations:^{
        superior.frame = CGRectMake(0, 710, 1024,500);
        ribbon.frame = CGRectMake(480, 685, 70,70);
        inferior.frame = CGRectMake(0, 750, 1024,500);}];

    [self.view bringSubviewToFront:inferior];

}
}

では、ユーザーが特定のオブジェクトではなく画面に触れたことをどのように検出できますか?

4

1 に答える 1

3

実際には、タッチ ポイントが特定のオブジェクト上にない場合、CGRectContainsPoint は false を返します。タッチポイントがリボンにあるかどうかを確認したいとします。「!」だけです。で十分です。

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];

    if (CGRectContainsPoint(ribbon.frame, location) || CGRectContainsPoint(inferior.frame,     location) || CGRectContainsPoint(superior.frame, location) & (pujat==YES)){

        if(!CGRectContainsPoints(ribbon.frame,location))
            NSLog("Touch point is not on ribbon");

        pujat=NO;
        [UIView animateWithDuration:0.25 animations:^{
        superior.frame = CGRectMake(0, 710, 1024,500);
        ribbon.frame = CGRectMake(480, 685, 70,70);
        inferior.frame = CGRectMake(0, 750, 1024,500);}];
        [self.view bringSubviewToFront:inferior];
    }
}
于 2013-04-30T22:06:05.157 に答える