1

如何找到被拖动元素的方向?我希望 uibutton 可以向左或向右拖动。我可以移动对象,但我想识别元素被拖动的方向。

这是我的代码

#import "SelectAnswerUIVIewController.h"

@implementation SelectAnswerUIVIewController

@synthesize cardViewOne;
@synthesize cardViewTwo;
@synthesize cardViewThree;
@synthesize cardViewFour;
@synthesize cardViewFive;

@synthesize buttonCardOne;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


// --------------------------  image animation methods ----------------------- //
// rotate image view
- (void)rotateImage:(UIButton *)image duration:(NSTimeInterval)duration 
              curve:(int)curve degrees:(CGFloat)degrees
{
    // Setup the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationCurve:curve];
    [UIView setAnimationBeginsFromCurrentState:YES];

    // The transform matrix
    CGAffineTransform transform = 
    CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
    image.transform = transform;

    // Commit the changes
    [UIView commitAnimations];
}



- (IBAction)rotateImageLeft:(id)sender;
{
    NSLog(@"DRAG LEFT CALLED");
    [self rotateImage:buttonCardOne duration:3.0 
                curve:UIViewAnimationCurveEaseIn degrees:180];

    [self rotateImage:buttonCardOne duration:3.0 
                curve:UIViewAnimationCurveEaseIn degrees:-180];

}


- (IBAction)rotateImageRight:(id)sender;
{
    NSLog(@"DRAG RIGHT CALLED");
    [self rotateImage:buttonCardOne duration:3.0 
                curve:UIViewAnimationCurveEaseIn degrees:-180];

}


@end
4

0 回答 0