본문 바로가기

ios aos 개발/iPhone

[iPhone] Uivew 밀는 효과

반응형

******controller.h
//******************************************************//
IBOutlet    UIView *menuView;
//******************************************************// 


******controller.m
//******************************************************//  

- (void)viewDidLoad
{
  UIPanGestureRecognizer* drg = [[UIPanGestureRecognizer alloc]

initWithTarget:self

                                                                          action:@selector(dragGesutreMethod:)];//내가 만든 함수

    [menuView addGestureRecognizer:drg];//이동 시킬 뷰에 제스쳐 함수 추가

    [drg release];

....
}
 
 -(IBAction)dragGesutreMethod:(UIGestureRecognizer*)sender

{

    CGPoint touchedpt = [sender locationInView:self.menuView];//menuview내에서 클릭된 좌표

    startPt = touchedpt;

    

    if (movingPt.x < 60 || movingPt.x > -60 ) {

        if (startPt.x < 150) {

            NSLog(@"moving to right, touch point is %d",startPt.x);

            [UIView beginAnimations:nil context:nil];

            [UIView setAnimationDuration:1];

            CGAffineTransform transform = CGAffineTransformMakeTranslation(endPt.x, 0.0);

            [[self menuView] setTransform:transform];

            if(movingPt.x < 20)

                movingPt.x += 3;

            CGAffineTransform transform2 = CGAffineTransformMakeTranslation(movingPt.x, 0.0);

            [[self menuView] setTransform:transform2];

            [UIView commitAnimations];

            

        } else {

            NSLog(@"moving to left touch point is %f, pt point is %d",startPt.x);

            [UIView beginAnimations:nil context:nil];

            [UIView setAnimationDuration:1];

            CGAffineTransform transform = CGAffineTransformMakeTranslation(endPt.x, 0.0);            [[self menuView] setTransform:transform];

            if(movingPt.x> -20)

                movingPt.x -= 3;

            CGAffineTransform transform2 = CGAffineTransformMakeTranslation(movingPt.x, 0.0);

            [[self menuView] setTransform:transform2];        

            [UIView commitAnimations];

        }

        endPt.x = movingPt.x;        

    }

}