buttonMoveViewController.h
#import <UIKit/UIKit.h> @interface buttonMoveViewController : UIViewController { IBOutlet UIImageView *pic; } @property(nonatomic, retain) UIImageView *pic; -(IBAction)moveUp:(id)sender; -(IBAction)moveDown:(id)sender; -(IBAction)moveLeft:(id)sender; -(IBAction)moveRight:(id)sender; @end
buttonMoveViewController.m
#import "buttonMoveViewController.h" @implementation buttonMoveViewController @synthesize pic; -(IBAction)moveUp:(id)sender{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGPoint center = pic.center; if(center.y > 0){ center.y -= 10; pic.transform = CGAffineTransformMakeScale(.35, 35); center.y -= 10; pic.transform = CGAffineTransformMakeScale(1, 1); pic.center = center; } } -(IBAction)moveDown:(id)sender{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGPoint center = pic.center; if(center.y < 300){ center.y += 10; pic.transform = CGAffineTransformMakeScale(.35, 35); center.y += 10; pic.transform = CGAffineTransformMakeScale(1, 1); pic.center = center; } } -(IBAction)moveLeft:(id)sender{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGPoint center = pic.center; if(center.x > 0){ center.x -= 10; pic.transform = CGAffineTransformMakeScale(.35, 35); center.x -= 10; pic.transform = CGAffineTransformMakeScale(1, 1); pic.center = center; } } -(IBAction)moveRight:(id)sender{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGPoint center = pic.center; if(center.x < 300){ center.x += 10; pic.transform = CGAffineTransformMakeScale(.35, 35); center.x += 10; pic.transform = CGAffineTransformMakeScale(1, 1); pic.center = center; } } - (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 { [pic release]; [super dealloc]; } @end
詳解 Objective-C 2.0 改訂版: 荻原 剛志 | iPhoneプログラミングUIKit詳解リファレンス: 所 友太, 京セラコミュニケーションシステム株式会社 | iPhone SDK アプリケーション開発ガイド: Jonathan Zdziarski, 近藤 誠 (監訳), 武舎 広幸, 武舎 るみ |
0 件のコメント:
コメントを投稿