• 长按事件--UILongPressGestureRecognizer


    //
    //  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

  • 相关阅读:
    2014 年最热门的国人开发开源软件TOP 100
    欢迎访问李培冠博客
    Go语言学习之路(持续更新)
    租房项目 获取地区信息服务
    租房项目 启动前的处理
    一步步带你用 FastDFS 搭建文件管理系统 详细的不得鸟
    golang 两个go程轮流打印一个切片
    golang 拷贝大切片一定比小切片代价大吗
    matlab 如何把数组A中与数组B中元素相同的元素删除
    golang 如何翻转含有中文 数字 英文字母等任意字符串
  • 原文地址:https://www.cnblogs.com/zhwl/p/2861512.html
Copyright © 2020-2023  润新知