- ViewにUITapGestureRecognizerを登録
- UITapGestureRecognizerのviewプロパティに登録したViewが保管されている
- UITapGestureRecognizerによりタップを検出
- ターゲットアクションに指定したメソッドを実行(Viewをスライドさせる)
#import "StudyAppDelegate.h"
@implementation StudyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//myViewの作成
UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(self.window.bounds.size.width - 44, 50, 300, 300)];
myView.backgroundColor = [UIColor blueColor];
[self.window addSubview:myView];
// ジェスチャーを見張る。ターゲットアクションを指定して初期化。
UITapGestureRecognizer* myTapGestureRecognizer
= [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(myMethod:)];
// タップを見張りたいUIViewに追加する。
[myView addGestureRecognizer:myTapGestureRecognizer];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
// タップされた時の処理。
-(void)myMethod:(UITapGestureRecognizer*)tapGestureRecognizer
{
UIView* tappedView = tapGestureRecognizer.view;
CGRect frame = tappedView.frame;
frame.origin.x = 10;
tappedView.frame = frame;
}
コメント