//
// 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. IIS配置相关

    转:让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求 http://www.cnblogs.com/dudu/archive/2009/11/10/160 ...

  2. plupload上传插件在SpringMVC中的整合

    前言:近期在给学院的站点做一个加入附件的功能,首先到了某某邮箱看了一下.简单有用.可是是flash做的,无法拷贝.就仅仅好上网找插件了.经过筛选.最终找到plupload这款插件(其实有的编辑器自带加 ...

  3. 0c-42-ARC模式下如何兼容非ARC的类

    1.ARC模式下如何兼容非ARC的类 让程序兼容ARC和非ARC部分.转变为非ARC -fno-objc-arc 2.将MRC转换为ARC ARC也需要考虑循环引用问题:一端用strong,一端用we ...

  4. Spark目录

    1. Spark1.0.0 应用程序部署工具spark-submit 2. Spark Streaming的编程模型 3. 使用java api操作HDFS文件 4. 用SBT编译Spark的Word ...

  5. 函数查询(Function Query)

    函数查询 可以利用 numeric字段的值 或者 与字段相关的的某个特定的值的函数,来对文档进行评分. 1.    使用函数查询的方法 这里主要有三种方法可以使用函数查询,这三种s方法都是通过solr ...

  6. 通用权限管理系统接口文档V4.2 版本之角色管理功能介绍

    角色功能维护界面:可实现添加.修改.删除角色,向角色添加或删除人员,角色具有哪些菜单的管理功能.

  7. Handsontable 学习笔记-Methods

    Handson: 亲自实践 先给出数据源和基本配置: var data =[ ["A1","B1","C1","D1"] ...

  8. 【Linux/Ubuntu学习4】ubuntu 下面安装 vim 的问题

    ubuntu 下面安装 vim 的问题 1.输入vim时,显示: 程序“vim”已包含在以下软件包中: * vim * vim-gnome * vim-tiny * vim-gtk * vim-nox ...

  9. json数据处理技巧(字段带空格、增加字段)

    1.json数据的正常取值:json[i].fieldName 2.json数据的字段带空格:eval('json[' + i + ']["' + field + '"]') 3. ...

  10. python学习好书推荐

    1.  编程小白的第一本 Python 入门书 http://www.ituring.com.cn/book/1863 点评:知识体系全面,作者也是功底深厚.对全面了解python非常有帮助.入门级推 ...