UI_手势

这篇博客介绍了如何在iOS应用中实现各种UI手势,包括轻拍手势用于隐藏键盘和点击头像,旋转手势、捏合手势和平移手势用于图片操作,以及长按手势的实现。通过这些手势,开发者可以增强用户界面的交互性。
摘要由CSDN通过智能技术生成

#import "AppDelegate.h"

#import "ViewController.h"

#import "SecondViewController.h"


@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

//--------------------------------------------------------------------------

    ViewController *viewController = [[ViewController alloc]init];

    self.window.rootViewController = viewController;

    

//--------------------------------------------------------------------------

//    SecondViewController  *secondVC = [[SecondViewController alloc]init];

//    self.window.rootViewController = secondVC;


//--------------------------------------------------------------------------

    

    

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}




#import "ViewController.h"

#import "TapView.h"


@interface ViewController ()<UIGestureRecognizerDelegate>


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

//--------------------------------------------------------------------------

    //  点击空白处回收键盘,通过轻拍手势

    UITextField *myTextField = [[UITextField alloc]initWithFrame:CGRectMake(150 ,200, 150, 30)];

    myTextField.borderStyle = UITextBorderStyleRoundedRect;

    myTextField.placeholder = @"测试轻拍手势";

    [self.view addSubview:myTextField];

    

    //为当前界面增加轻拍手势,是的点击时可以回收键盘

    //初始化轻拍手势

    //回调方法所带的参数为手势本身

    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenKeyBoard:)];

    //将手势添加到视图,只要视图的用户交互打开,不是关闭的,就可以响应手势

    [self.view addGestureRecognizer:tapGestureRecognizer];


//--------------------------------------------------------------------------

    //给头像上添加轻拍手势

    UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 250, 100, 100)];

    [headImageView setImage:[UIImage imageNamed:@"zhang.png"]];

    headImageView.layer.borderWidth = 4;

    headImageView.layer.cornerRadius = 50;

    headImageView.layer.masksToBounds = YES;

    [self.view addSubview:headImageView];

    

    //headImageView添加手势

        //初始化轻拍手势

        //将手势团添加到imaheView

    UITapGestureRecognizer *tapGestureRecognizer1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImage:)];

    

    [self.view addGestureRecognizer:tapGestureRecognizer1];

  

    [headImageView setUserInteractionEnabled:YES];

    [self.view setUserInteractionEnabled:YES];

    //触发回调方法所需要的勤工爱次数

    tapGestureRecognizer1.numberOfTouchesRequired = 5;

    //需要触摸对象的个数

    tapGestureRecognizer1.numberOfTouchesRequired = 2;

    

    

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];

    //扫动方向(枚举值)

    swipe.direction =(UISwipeGestureRecognizerDirectionUp |UISwipeGestureRecognizerDirectionDown);

    [self.view addGestureRecognizer:swipe];

//--------------------------------------------------------------------------

   //轻扫手势

    UIScreenEdgePanGestureRecognizer *pan =[[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];

    pan.edges = UIRectEdgeRight;

    [self.view addGestureRecognizer:pan];

    

    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值