zoukankan      html  css  js  c++  java
  • UI1_UITouch

    //
    //  ViewController.m
    //  UI1_UITouch
    //
    //  Created by zhangxueming on 15/7/9.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "ViewController.h"
    #import <AudioToolbox/AudioToolbox.h>
    
    @interface ViewController ()
    {
        UIView *_touchView;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        _touchView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        _touchView.backgroundColor = [UIColor redColor];
        //打开用户交互
        _touchView.userInteractionEnabled = YES;
        [self.view addSubview:_touchView];
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"开始触摸");
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"开始移动");
        //获取一个触摸点
        UITouch *touch = [touches anyObject];
        //获取触摸点在view中的坐标
        CGPoint point = [touch locationInView:self.view];
        _touchView.center = point;
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"触摸结束");
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"触摸取消");
    }
    
    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        NSLog(@"开始摇动");
        SystemSoundID soudID;
        //创建soundID;
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"音效" ofType:@"caf"]], &soudID);
        //播放soundID;
        AudioServicesPlaySystemSound(soudID);
        //伴随震动
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
        [UIView animateWithDuration:0.3 animations:^{
            CGRect frame = self.view.frame;
            frame.origin.x+=50;
            self.view.frame = frame;
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.3 animations:^{
                CGRect frame = self.view.frame;
                frame.origin.x-=100;
                self.view.frame = frame;
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:0.3 animations:^{
                    CGRect frame = self.view.frame;
                    frame.origin.x+=50;
                    self.view.frame = frame;
                }];
            }];
        }];
    }
    
    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        NSLog(@"摇动结束");
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    
  • 相关阅读:
    VS2008 查找失效怎么办
    Winfrom弹出下拉编辑控件,DataGridView弹出查询对话框下拉录入,支持TextBox
    修改SQL Server 2005的默认端口
    C#操作XML小结
    金蝶KIS系列 KISBOS 二次开发学习资料 例子 习题 讲解
    Datawindow.net中实现让当前行选中,并且当前行以其他颜色显示
    sqlserver 截取字符串
    python3定时爬虫
    linux下安装pyenv及使用pyenv管理不同的python版本
    CentOS7下安装mysql最快捷方式及mysql远程访问连接实现
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638898.html
Copyright © 2011-2022 走看看