码迷,mamicode.com
首页 > 移动开发 > 详细

app 摇一摇功能

时间:2015-08-09 20:35:48      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

1.重写canBecomeFirstResponder ,并返回YES

-(BOOL)canBecomeFirstResponder{
    return YES;
}

2.重写UIResponder的三个方法

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"在摇了");
}

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    
    if (event.subtype == UIEventSubtypeMotionShake) {
        NSLog(@"stop");
        
        int i = arc4random_uniform(12);
        NSLog(@"%d",i);
        NSString *str = nil;
        if (i == 3) {
            str = @"你运气真好,中奖了";
        }else{
            str = @"你还有3次机会";
        }
        
        UIAlertView *yaoyao = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:str delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [yaoyao show];
    }
    
}

-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"取消");
}

 

app 摇一摇功能

标签:

原文地址:http://www.cnblogs.com/gulong/p/4716116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!