js06金沙官网登录-js06.com-欢迎您

来自 计算机 2019-11-21 22:29 的文章
当前位置: js06金沙官网登录-js06.com-欢迎您 > 计算机 > 正文

【代码笔记】iOS-单击手势的添加,笔记ios-单击手

【代码笔记】iOS-单击手势的添加,笔记ios-单击手势

一,效果图。

金沙官网登录 1

金沙官网登录,二,工程图。

金沙官网登录 2

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UIGestureRecognizerDelegate>

@end

 

RootViewController.m

金沙官网登录 3

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //添加背景
    [self addView];
}
#pragma -mark -functions
//添加背景
-(void)addView
{
    self.title=@"单击手势的添加";

    UIView *parentView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
    parentView.backgroundColor=[UIColor redColor];
    [self.view addSubview:parentView];

    //单击的手势
    UITapGestureRecognizer *tapRecognize = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
    tapRecognize.numberOfTapsRequired = 1;
    tapRecognize.delegate = self;
    [tapRecognize setEnabled :YES];
    [tapRecognize delaysTouchesBegan];
    [tapRecognize cancelsTouchesInView];

    [self.view addGestureRecognizer:tapRecognize];

}
#pragma UIGestureRecognizer Handles
-(void) handleTap:(UITapGestureRecognizer *)recognizer
{
    NSLog(@"---单击手势-------");
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

金沙官网登录 4

 

一,效果图。 二,工程图。 三,代码。 RootViewController.h #import UIKit/UIKit.h @interface Roo...

本文由js06金沙官网登录-js06.com-欢迎您发布于计算机,转载请注明出处:【代码笔记】iOS-单击手势的添加,笔记ios-单击手

关键词: