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的更多相关文章
随机推荐
- kickstart一键自动安装Linux系统
kickstart,无人值守,自动安装系统.本文介绍kickstart的用法. #安装系统的信息——可以参考 [root@larrywen pdf]# vim ~/anaconda-ks.cfg 第一 ...
- [Angular 2] Generate and Render Angular 2 Template Elements in a Component
Angular 2 Components have templates, but you can also create templates inside of your templates usin ...
- javascript 拷贝
拷贝简单分为浅拷贝与深度拷贝,即给定一个对象,生成一个相同的对象. 浅拷贝 function copy(source,destiny){ destiny = destiny || {}; if(typ ...
- oralce 函数 FOR windows 跟踪神器
https://github.com/dennis714 http://www.yurichev.com
- 字典树(Trie)的java实现
一.定义 字典树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用 ...
- Golang学习 - bytes 包
------------------------------------------------------------ 对于传入 []byte 的函数,都不会修改传入的参数,返回值要么是参数的副本, ...
- 记录一下bing的图片 - 升级版冰糖葫芦
记录一下bing的图片 - 升级版冰糖葫芦
- C# 自定义重绘TextBox
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- java和C#中 定义变量,加一个小括号是什么意思。。。
在群里灌水发现,有人这样定义字符串,感觉很好奇..又问了群友,群友说这样定义没问题.. String strtemp = ("test"); 我自己试了下,java和C#都可以,C ...
- 再识C中的结构体
在前面认识C中的结构体中我介绍了结构体的基础知识,下面通过这段代码来回顾一下: #include<stdio.h> #define LEN 20 struct Student{ //定义结 ...