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 xcodehttp://www.youtube.com/watch?v=QD7dSZaj3J0&hd=1
![]() 詳解 Objective-C 2.0 改訂版: 荻原 剛志 | ![]() iPhoneプログラミングUIKit詳解リファレンス: 所 友太, 京セラコミュニケーションシステム株式会社 | ![]() iPhone SDK アプリケーション開発ガイド: Jonathan Zdziarski, 近藤 誠 (監訳), 武舎 広幸, 武舎 るみ |



0 コメント:
コメントを投稿