长按事件--UILongPressGestureRecognizer
2012-06-04 18:21
302 查看
//
// touchViewController.m
// touch
//
// Created by joe visen on 11-9-21.
// Copyright 2011 mjrj.com. All rights reserved.
//
#import"touchViewController.h"
@implementation touchViewController
- (void)loadView{
[super loadView];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showResetMenu:)];
[self.view addGestureRecognizer:longPressGesture];
[longPressGesture release];
//[view release];
}
- (void)showResetMenu:(UILongPressGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
UIMenuController *menuController = [UIMenuController sharedMenuController];
UIMenuItem *resetMenuItem = [[UIMenuItem alloc] initWithTitle:@"Reset" action:@selector(resetPiece:)];
CGPoint location = [gestureRecognizer locationInView:[gestureRecognizer view]];
[self becomeFirstResponder];
[menuController setMenuItems:[NSArray arrayWithObject:resetMenuItem]];
[menuController setTargetRect:CGRectMake(location.x, location.y, 0, 0) inView:[gestureRecognizer view]];
[menuController setMenuVisible:YES animated:YES];
//pieceForReset = [gestureRecognizer view];
[resetMenuItem release];
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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
// touchViewController.m
// touch
//
// Created by joe visen on 11-9-21.
// Copyright 2011 mjrj.com. All rights reserved.
//
#import"touchViewController.h"
@implementation touchViewController
- (void)loadView{
[super loadView];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showResetMenu:)];
[self.view addGestureRecognizer:longPressGesture];
[longPressGesture release];
//[view release];
}
- (void)showResetMenu:(UILongPressGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
UIMenuController *menuController = [UIMenuController sharedMenuController];
UIMenuItem *resetMenuItem = [[UIMenuItem alloc] initWithTitle:@"Reset" action:@selector(resetPiece:)];
CGPoint location = [gestureRecognizer locationInView:[gestureRecognizer view]];
[self becomeFirstResponder];
[menuController setMenuItems:[NSArray arrayWithObject:resetMenuItem]];
[menuController setTargetRect:CGRectMake(location.x, location.y, 0, 0) inView:[gestureRecognizer view]];
[menuController setMenuVisible:YES animated:YES];
//pieceForReset = [gestureRecognizer view];
[resetMenuItem release];
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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
相关文章推荐
- 长按事件--UILongPressGestureRecognizer
- 长按事件--UILongPressGestureRecognizer
- IOS长按事件--UILongPressGestureRecognizer
- 长按事件--UILongPressGestureRecognizer
- 长按事件--UILongPressGestureRecognizer
- 启用长按事件 UILongPressGestureRecognizer
- iPhone开发之手势的预习—— UITapGestureRecognizer pinch捏合 longPress长按 rotation旋转
- ios 长按事件 ( UILongPressGestureRecognizer长按事件 (2013-02-21 16:10:41)转载▼
- UITapGestureRecognizer和UITableView点击事件冲突问题
- 手势 UILongPressGestureRecognizer 长按手势
- 给控件添加单击事件--UITapGestureRecognizer
- 给UIimageView添加UITapGestureRecognizer手势点击事件
- UITapGestureRecognizer和UIButton的点击事件冲突的解决办法
- UILongPressGestureRecognizer的介绍
- Swift 简单封装UISwipeGestureRecognizer + 闭包回调监听事件,便于不同场景的 UIView调用
- UILongPressGestureRecognizer 触发两次解决
- uilongPressGestureRecognizer 的两次(多次)触发
- 解决UITapGestureRecognizer 与 UITableView 点击事件冲突
- 将UILongPressGestureRecognizer写成Block
- UILongPressGestureRecognizer 执行两次的问题