2016-10-07 6 views
-1

このアニメーションをスワイプして機能させることができません。 ここまでは私のコードです。アニメーションのみですが、画面上をスワイプするとオブジェクトが機能しません。UIビューのアニメーションを上下にスワイプします

ViewController.m 
// notificationView 

// 

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NotificationView *notifications= [[NotificationView alloc]    initWithFrame:CGRectMake(200,200,200,200)]; 
     notifications.backgroundColor =[ UIColor blueColor]; 
     [self.view addSubview:notifications]; 

    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer   alloc]initWithTarget:self action: 
    @selector(swipeUp:)]; 
    [notifications addGestureRecognizer:swipeUp]; 

    swipeUp.direction=UISwipeGestureRecognizerDirectionUp; 

    UISwipeGestureRecognizer *swipeDown=[[UISwipeGestureRecognizer   alloc]initWithTarget:self action: 
    @selector(swipeDown:)]; 

    swipeDown.direction=UISwipeGestureRecognizerDirectionDown; 
    [notifications addGestureRecognizer:swipeDown]; 

    [UIView animateWithDuration:0.5 animations:^{ 
     notifications.center=CGPointMake(150,150);}]; }; 

    -(void) swipeUp:(id) sender { 
    UISwipeGestureRecognizer *swipe = (UISwipeGestureRecognizer *) sender;} 

    -(void) swipeDown:(id) sender { } 



@end 
+0

デリゲートが不足していると思います。ヘッダーにUIGestureRecognizerDelegateを設定します。 –

答えて

1

この作業を完璧にお試しください。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    notifications = [[UIView alloc] initWithFrame:CGRectMake(200,200,200,200)]; 
    notifications.backgroundColor =[ UIColor blueColor]; 
    [self.view addSubview:notifications]; 

    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action: 
             @selector(swipeUp:)]; 
    [notifications addGestureRecognizer:swipeUp]; 

    swipeUp.direction=UISwipeGestureRecognizerDirectionUp; 

    UISwipeGestureRecognizer *swipeDown=[[UISwipeGestureRecognizer alloc]initWithTarget:self action: 
             @selector(swipeDown:)]; 

    swipeDown.direction=UISwipeGestureRecognizerDirectionDown; 
    [notifications addGestureRecognizer:swipeDown]; 

    [UIView animateWithDuration:0.5 animations:^{ 
     notifications.center=CGPointMake(150,150); 
    }]; 
} 

-(void) swipeUp:(id) sender { 

    [self animationOfObject:150 yVlaue:150]; 
} 

-(void) swipeDown:(id) sender { 

    [self animationOfObject:150 yVlaue:300]; 
} 

-(void)animationOfObject:(float)xValue yVlaue:(float)yValue 
{ 
    [UIView animateWithDuration:0.5 animations:^{ 
     notifications.center=CGPointMake(xValue,yValue); 
    }]; 
} 
+0

あなたが私の答えに満足したら、私の答えを正しくマークするのを忘れないでください。 –

関連する問題