Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UI视图动画向上或向下滑动_Ios_Objective C_Iphone - Fatal编程技术网

Ios UI视图动画向上或向下滑动

Ios UI视图动画向上或向下滑动,ios,objective-c,iphone,Ios,Objective C,Iphone,我在获取上下滑动的动画时遇到问题。 这是到目前为止我的代码。在屏幕上滑动时,它只会设置动画,但对象不起作用 ViewController.m // notificationView // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; Notif

我在获取上下滑动的动画时遇到问题。 这是到目前为止我的代码。在屏幕上滑动时,它只会设置动画,但对象不起作用

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

试试这个,它的工作很完美

  - (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);
    }];
}

我想你和代表失踪了。在标题中设置UIgestureRecognitizerDelegate。如果您对我的答案感到满意,请不要放弃正确标记我的答案。