源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

IOS 单击手势的添加实现代码

  • 时间:2020-12-18 03:10 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:IOS 单击手势的添加实现代码
[b]IOS 单击手势的添加实现代码[/b] [b]一,效果图。[/b] [img]http://files.jb51.net/file_images/article/201705/2017516111029705.jpg?2017416111041[/img] [b]二,工程图。[/b] [img]http://files.jb51.net/file_images/article/201705/2017516111104162.jpg?2017416111122[/img] [b]三,代码。[/b] RootViewController.h
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UIGestureRecognizerDelegate>

@end

 RootViewController.m
#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.
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部