UI_手势

#import "MainViewController.h"

@interface MainViewController ()
@property(nonatomic, retain)UIImageView *imageView;
@property(nonatomic, retain)UIAlertView *alertView;
@end

@implementation MainViewController

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

    // UIImageView
    UIImage *image = [UIImage imageNamed:@"22.jpg"];
    self.imageView = [[UIImageView alloc]initWithImage:image];
    self.imageView.frame = CGRectMake(80, 100,200, 300) ;
    [self.view addSubview:self.imageView];
    [_imageView release];

    // 把图片的用户交互打开,它默认是关闭的,此外还有一个空间是label
    self.imageView.userInteractionEnabled = YES;

    //手势的作用


// 1.点击
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    // 2.设置点击几次才会触发方法
    tap.numberOfTapsRequired = 2;
    // 3.设置几根手指进行点击
    tap.numberOfTouchesRequired = 2;
    // 4.将手势添加到对应的图片上
    [self.imageView addGestureRecognizer:tap];
    [tap release];


//  2.长按
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
    // 设置长按触发的最小时间
    longPress.minimumPressDuration = 2;
    // 允许用户手指在长按过程中允许移动的距离
    longPress.allowableMovement = 200;
    // 把手势添加到图片上
    [self.imageView addGestureRecognizer:longPress];
    [longPress release];

//  3.旋转
    // 创建一旋转的手势
    UIRotationGestureRecognizer *rotaTion = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    // 把手势放到对应的图片上
    [self.imageView addGestureRecognizer:rotaTion];
    // 释放
    [rotaTion release];


// 4.捏合
    // 创建
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
    // 放到图片上
    [self.imageView addGestureRecognizer:pinch];
    // 创建
    [pinch release];

// 5.拖拽
    // 创建
    UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureAction:)];
    // 添加手势
    [self.imageView addGestureRecognizer:panGesture];
    // 释放
    [panGesture release];


// 6.轻扫
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
    [self.imageView addGestureRecognizer:swipe];
    [swipe release];
    //  轻扫的方向
      //向右
    swipe.direction = UISwipeGestureRecognizerDirectionRight ;


// 7.屏幕边际手势,iOS7.0之后的手势
//UIScreenEdgePanGestureRecognizer





}
#pragma mark  点击的方法
- (void)tapAction:(UITapGestureRecognizer *)tap{
    NSLog(@"测试一下点击手势");
    self.imageView.image = [UIImage imageNamed:@"33.jpg"];
}


#pragma mark 长按对应的响应方法
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress{
    /*长按的状态
    longPress.state*/
    //长安后弹出一个UIAlertView


    if (!self.alertView) {
        self.alertView = [[UIAlertView alloc]initWithTitle:nil message:@"跳转" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [self.alertView show];
        [_alertView release];
        self.alertView = nil;

    }
}

#pragma mark 通过图片的旋转手势,让图片发生旋转
- (void)rotationAction:(UIRotationGestureRecognizer *)rotation{
// 可以通过手势获取手势添加的视图是哪一个
    UIImageView *imageView = (UIImageView *)rotation.view;
// 进行旋转的操作
    //通过视图的transform属性,让视图进行旋转
//    imageView.transform = CGAffineTransformMakeRotation(rotation.rotation);
    imageView.transform = CGAffineTransformRotate(imageView.transform, rotation.rotation);
    rotation.rotation = 0;
}

#pragma mark 捏合, 缩放图片
- (void)pinchAction:(UIPinchGestureRecognizer *)pinch{
    // 通过手势找到对应的视图
    UIImageView *imageView = (UIImageView *)pinch.view;
    // 通过transform改变图片尺寸
    imageView.transform = CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);
    // 为了防止手势的变化让图片直接消失
    pinch.scale = 1;


}

#pragma mark 通过拖拽的手势,让视图随着手势的移动而移动
- (void)panGestureAction:(UIPanGestureRecognizer *)panGest{
    // 通过手势找视图
    UIImageView *imageView = (UIImageView *)panGest.view;
    // 通过手势获得经过的点
    CGPoint p = [panGest translationInView: imageView];
    // 设置移动的位置
    imageView.transform = CGAffineTransformTranslate(imageView.transform, p.x, p.y);
    // 为了防止手势在操作的时候在视图消失
    [panGest setTranslation:CGPointZero inView:imageView];



}


#pragma mark 轻扫
- (void)swipeAction:(UISwipeGestureRecognizer *)swipe{
    if (swipe.direction ==  UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"向右");
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation



@end
// This file was generated by SquareLine Studio // SquareLine Studio version: SquareLine Studio 1.4.2 // LVGL version: 9.1.0 // Project name: SquareLine_Project #include "../ui.h" void ui_Screen3_screen_init(void) { ui_Screen3 = lv_obj_create(NULL); lv_obj_remove_flag(ui_Screen3, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_image_src(ui_Screen3, &ui_img_bg_png, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_color(ui_Screen3, lv_color_hex(0x00FF00), LV_PART_SCROLLBAR | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_Screen3, 255, LV_PART_SCROLLBAR | LV_STATE_DEFAULT); lv_obj_set_style_bg_image_src(ui_Screen3, &ui_img_game_png, LV_PART_SCROLLBAR | LV_STATE_DEFAULT); ui_Button2 = lv_button_create(ui_Screen3); lv_obj_set_width(ui_Button2, 100); lv_obj_set_height(ui_Button2, 50); lv_obj_set_x(ui_Button2, -456); lv_obj_set_y(ui_Button2, -277); lv_obj_set_align(ui_Button2, LV_ALIGN_CENTER); lv_obj_add_flag(ui_Button2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_remove_flag(ui_Button2, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_Button2, lv_color_hex(0xFF8200), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_Button2, 100, LV_PART_MAIN | LV_STATE_DEFAULT); ui_Label3 = lv_label_create(ui_Screen3); lv_obj_set_width(ui_Label3, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_Label3, LV_SIZE_CONTENT); /// 1 lv_obj_set_x(ui_Label3, -458); lv_obj_set_y(ui_Label3, -277); lv_obj_set_align(ui_Label3, LV_ALIGN_CENTER); lv_label_set_text(ui_Label3, "退出"); lv_obj_set_style_text_font(ui_Label3, &ui_font_chinese38, LV_PART_MAIN | LV_STATE_DEFAULT); // 分数标签 ui_ScoreLabel = lv_label_create(ui_Screen3); lv_label_set_text(ui_ScoreLabel, "Score: 0"); lv_obj_align(ui_ScoreLabel, LV_ALIGN_TOP_RIGHT, -10, 10); lv_obj_set_style_text_font(ui_ScoreLabel, &lv_font_montserrat_28, LV_PART_MAIN); // 28像素字体大小 lv_obj_set_style_text_color(ui_ScoreLabel, lv_color_hex(0xFFFFFF), LV_PART_MAIN); // 白色字体 lv_obj_set_style_text_opa(ui_ScoreLabel, LV_OPA_COVER, LV_PART_MAIN); // 完全不透明 lv_obj_add_event_cb(ui_Button2, ui_event_Button2, LV_EVENT_ALL, NULL); } 在此背景下调用游戏函数实现切水果游戏,结合现有代码
08-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值