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的更多相关文章
随机推荐
- 【JavaScript】HTML5存储方案
1.Web SQL 2.IndexedDB 3.Local Storage 4.Session Storage 5.Cookies 6.Application Cache
- BigDecimal带精度的运算的两篇文章
转自:http://guoliangqi.iteye.com/blog/670908 之前提到过在商业运算中要使用BigDecimal来进行相关的钱的运算(java中关于浮点运算需要注意的 ),可是实 ...
- SQL SERVER-Delete和Truncate的区别
背景: 一般在删除表数据时候,通常会有执行两个SQL语句:delete和truncate,有条件的删除我们平时都会用delete,而如果全部删除,那我们通常都会选择truncate,因为这 ...
- Disable right click on the website
Many developers/website owners like to keep their website images personal and don't want anyone to c ...
- c++ 设计模式3 (重构技法 Template Method)
1. 重构 面向对象设计模式是“好的面向对象设计”,所谓“好的面向对象设计”指的是那些可以满足 “应对变化,提高复用”的设计. 设计模式的要点是“寻找变化点,然后在变化点处应用设计模式,从而更好地理解 ...
- J2SE J2EE J2ME的区别
J2SE J2EE J2ME的区别 J2SE J2EE J2ME的区别多数编程语言都有预选编译好的类库以支持各种特定的功能,在Java中,类库以包(package)的形式提供,不同版本的Java提供不 ...
- c++11 Chrono时间库
c++11 Chrono时间库 http://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search=chrono ...
- 【JEMTER】后置处理器JSON Path Extractor获取server端返回的json中某项值
需求1:点击所有报表模板时,server端返回所有报表模板的ID(templateId),测试时需要下载某个模板生成的报表 需求2:点击单个报表模板时,server端返回这个报表模板下的所有报表ID( ...
- iphone开发之用lipo合并模拟器库和真机库,发布一个通用的静态库
转载自:http://blog.csdn.net/arthurchenjs/article/details/6044616 lipo lipo –create Release-iphoneos/lib ...
- QQ互联登陆出现(1054) Unknown column “conuintoken” in “field list”
在dz论坛中打开了QQ互联登录功能之后提示(1054) Unknown column conuintoken in field list 错误 我们看到sql 错误就是说没有conuintoken字了 ...