2011年6月4日土曜日

Xcode 表示されたイメージをDragする





dragImageViewController.h
#import <UIKit/UIKit.h>
interface dragImageViewController : UIViewController {
 
 UIImageView *ball;
 UILabel *xCoord;
 UILabel *yCoord;
 CGPoint startPoint;

}


@property(nonatomic, retain) IBOutlet UIImageView *ball;
@property(nonatomic, retain) IBOutlet UILabel *xCoord;
@property(nonatomic, retain) IBOutlet UILabel *yCoord;
@property CGPoint startPoint;

@end


dragImageViewController.m
#import "dragImageViewController.h"

@implementation dragImageViewController


@synthesize ball, xCoord, yCoord, startPoint;


-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
 
 UITouch *kick = [touches anyObject];
 
 startPoint = [kick locationInView:self.view];
 
 xCoord.text = [NSString stringWithFormat:@"X = %f", startPoint.x];
 yCoord.text = [NSString stringWithFormat:@"Y = %f", startPoint.y];
 
 ball.center = CGPointMake(startPoint.x, startPoint.y);
 
}

- (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.
}

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


- (void)dealloc {
    [super dealloc];
}

@end


参考

YouTube - 2.1 Touch and drag an image around the screen using TouchsMove - iPhone sdk xcode
http://www.youtube.com/watch?v=QD7dSZaj3J0&hd=1


0 コメント: