//
// 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

UI1_UITouch的更多相关文章

随机推荐

  1. Yeoman+Express+Angular在Linux上开发配置方法

    $mkdir ExpressWithAngularTest $cd ExpressWithAngularTest choose needed components you'd like to add ...

  2. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

  3. MySQL 5.7 深度解析: 临时表空间

    http://www.actionsky.com/docs/archives/159  2016年1月8日  杨涛涛 先来说说临时表的概念. 临时表顾名思义,就是临时的,用完销毁掉的表. 数据既可以保 ...

  4. kmp算法简明教程

    在字符串s中寻找模式串p的位置,这是一个字符串匹配问题. 举例说明: i = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 s = a b a a c a b a a a b a a ...

  5. C#使用Monitor类、Lock和Mutex类进行多线程同步

    在多线程中,为了使数据保持一致性必须要对数据或是访问数据的函数加锁,在数据库中这是很常见的,但是在程序中由于大部分都是单线程的程序,所以没有加锁的必要,但是在多线程中,为了保持数据的同步,一定要加锁, ...

  6. ASP.NET 批量更新

    ASP.NET三种常用批量操作: 一.SqlBulkCopy copy = new SqlBulkCopy("");(优先考虑 性能最优) SqlBulkCopy可以将一个Data ...

  7. tcpdump常用命令

    1. 只抓syn包 tcpdump -i eth1 'tcp[tcpflags] = tcp-syn' 2. 只抓ack包 tcpdump -nni xgbe1 dst host 191.168.10 ...

  8. 关于Google Chorme中字体小于12px的问题

    问题:当字体大小设置成小于12px时,Google chrome中字体的大小始终显示为12px. 而其他浏览器则没有这个问题. 这时只需要在要改变字体大小的元素中添加 -webkit-transfor ...

  9. label

    label的使用 以前只知道使用并没太注意一些细节 话说<label><input type="checkbox"/>5星</label>就可以 ...

  10. ASUS K751笔记本电脑使用U盘启动

    ASUS K751笔记本电脑缺省是不能使用U盘启动的.即使开机按ESC键出现启动设备选项菜单,选择了U盘也一样会从硬盘启动. 为此需进行如下步骤: 开机按F2进入bios如下设置: Security- ...