首先,在AppDelegate 里的 application:didFinishLaunchingWithOptions: 方法里添加如下声明,跟系统申请开启抖动:

[application setApplicationSupportsShakeToEdit:YES];

然后,在controller里面,添加类似的代码:


#pragma mark - shake to reload data

//TODO setShakeLayoutHidden

- (void)viewDidAppear:(BOOL)animated {
    [self becomeFirstResponder];
    [super viewDidAppear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self becomeFirstResponder];
    [super viewDidDisappear:animated];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [self setShakeLayoutHidden:NO];
}

- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [self setShakeLayoutHidden:YES];
}

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [self setShakeLayoutHidden:YES];
    if (event.subtype == UIEventSubtypeMotionShake) {
        //something happens
    }
}



请按需补全


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
L360管线管 Homepage
2012/06/05 12:12
这个抖动功能很给力的
分页: 1/1 第一页 1 最后页
发表评论
AD
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐