iPhone_TouchEvent のバックアップ差分(No.2) - アールメカブ

アールメカブ


iPhone_TouchEvent のバックアップ差分(No.2)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[Programming]]

[[ここ:http://ameblo.jp/xcc/day-20090326.html]]がとても参考になる.
   - (CGPoint)locationInView:(UIView *)view
locationInView:hogeは
指定したビュー hoge の座標系でレシーバ(タッチ)の現在の座標を返す。nilを指定した場合ウインドウの座標系になる。([[参照:http://profo.jp/wiki/index.php?UITouch#e2d7f1b0]])

これは hoge の現在の位置を,親ビューの座標系で返せ,ということか.
以下のループ構造でよく使われる.

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
	for (UITouch *touch in touches) {
		clickPos = [touch locationInView:self];
		break;
	}	
 }

ビューの座標系については[[ここ:http://son-son.sakura.ne.jp/programming/iphone_setframe_setzposition_s.html]]が詳しい

また以下は[[ここ:http://d.hatena.ne.jp/Chabashira/20080322/1206175764]]からの引用.

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
    // We only support single touches, so get the touch from allTouches
    UITouch *touch = [[event allTouches] anyObject];
 
    // Only move the placard view if the touch was in the placard view
    if ([touch view] != placardView)
    {
        // In case of a double tap outside the placard view, update the placard's display string
        if ([touch tapCount] == 2)
        {
            [placardView setupNextDisplayString];
        }
        return;
    }
    // Animate the first touch
    CGPoint touchPoint = [self convertPoint:[touch locationInView] fromView:placardView];
    CGPoint touchPoint = [self convertPoint:[touch locationInView:self] fromView:placardView];
    [self animateFirstTouchAtPoint:touchPoint];
 }

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
 {
    UITouch *touch = [[event allTouches] anyObject];
 
    // If the touch was in the placardView, move the placardView to its location
    if ([touch view] == placardView)
    {
        CGPoint location = [touch locationInView];
        CGPoint location = [touch locationInView:self];
        location = [self convertPoint:location fromView:placardView];
        placardView.center = location;
        return;
    }
 }

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
    UITouch *touch = [[event allTouches] anyObject];
 
    // If the touch was in the placardView, bounce it back to the center
    if ([touch view] == placardView)
    {
        // Disable user interaction so subsequent touches don't interfere with animation
        self.userInteractionEnabled = NO;
        [self animatePlacardViewToCenter];
        return;
    }
 }