首先,在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
    }
}



请按需补全
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐