微信的摇一摇是怎么实现的~发现原来 ios本身就支持
2012-09-10 21:50
567 查看
在 UIResponder中存在这么一套方法
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
这就是执行摇一摇的方法。那么怎么用这些方法呢?
很简单,你只需要让这个Controller本身支持摇动
同时让他成为第一相应者:
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplicationsharedApplication] setApplicationSupportsShakeToEdit:YES];
[selfbecomeFirstResponder];
}
然后去实现那几个方法就可以了
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//检测到摇动
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动结束
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
}
}
至于界面我就不写了~
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
这就是执行摇一摇的方法。那么怎么用这些方法呢?
很简单,你只需要让这个Controller本身支持摇动
同时让他成为第一相应者:
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplicationsharedApplication] setApplicationSupportsShakeToEdit:YES];
[selfbecomeFirstResponder];
}
然后去实现那几个方法就可以了
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//检测到摇动
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动结束
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
}
}
至于界面我就不写了~
相关文章推荐
- IOS开发中摇一摇是怎么实现的
- IOS开发之——类似微信摇一摇的功能实现
- iOS实现向多个社交网站(facebook,微信,微博,twitter等)分享的代码,支持iPhone和iPAD(分享链接编码)
- IOS怎么实现一个UITableView的下拉刷新
- Linux Centos 怎么安装更新根证书实现支持https访问
- iOS开发之微信聊天页面实现
- iOS微信朋友圈与摇一摇
- iOS第三方库Eureka实现定制动画详解(八):怎么写一个定制的Row?
- iOS中实现一个支持小数的星星评分组件
- iOS实现支持小数的星星评分组件实例代码
- 微信账号支持的格式(正则验证的方式JS实现)
- iOS 仿微信摇一摇
- IOS开发仿微信右侧弹出视图实现
- ios中纯手写代码怎么实现控件的自动布局(约束)
- android 类似微信的摇一摇实现
- Git 本身不支持对某一特定文件夹或者子目录的权限控制,但是可以通过子模块的形式间接实现
- 奔五的人学iOS:用swift实现获取拼音首字母,支持取一句话中每字拼音首字母
- iOS中的 摇一摇 功能实现
- iOS应用如何实现64位的支持
- iOS应用如何实现64位的支持