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
UI1_UITouch的更多相关文章
随机推荐
- Spring MVC整合Velocity
Velocity模板(VM)语言介绍 Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由j ...
- Java多线程:线程死锁
发生死锁的原因通常是两个对象的锁相互等待造成的. 以下用一个实例来构造这样的情况: package basic.e_deadlock; import org.apache.log4j.Logger; ...
- iOS开发——路径篇&混编路径与全局宏路径
混编路径与全局宏路径 最近在做东西的时候有一个地方要用到一个第三方库的,但是目前swift版的还没有找到,自己又不想写(其实是不会写),所以就想到了混编,但是中间出现了好多问题,其中印象最深的就是桥接 ...
- centos 服务器配置(二) 之ftp配置
Centos配置vsftpd服务器 1.通过yum来安装vsftpd [root@localhost ~]# yum -y install vsftpd 加-y是因为出现提示默认直接按Y.这里yum安 ...
- 【优先队列】HDU 1873——看病找医生
来源:点击打开链接 看路径记录的BFS之前,再看一遍优先队列的用法. 优先队列的排序规则可以用运算符重载的方式完成,通常意义下,应该用friend bool operator <进行重载. #i ...
- ecshop被加入了黑链
朋友一个ecshop网站被攻击了,查看代码如下: <?php $password = "1";//设置密码 error_reporting(E_ERROR); header( ...
- LeetCode18 4Sum
题意: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...
- rsync同步工具学习笔记
rsync同步工具 1.rsync介绍 rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.rsync软件适用于unix/linux/windows等多种操作 ...
- 【转】详解spring事务属性
转载自:http://blog.chinaunix.net/u1/55983/showart_2091761.html 7个传播行为,4个隔离级别, Spring事务的传播行为和隔离级别[transa ...
- 1.7.7 Spell Checking -拼写检查
1. SpellCheck SpellCheck组件设计的目的是基于其他,相似,terms来提供内联查询建议.这些建议的依据可以是solr字段中的terms,外部可以创建文本文件, 或者其实lucen ...