搖一搖-只需三步

//引頭文件

#import "AppDelegate.h"


//成爲第一響應者

- (void)viewDidLoad

{

    [super viewDidLoad];

    [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];

    [self becomeFirstResponder]; 

}


//實現方法

//檢測到搖動

- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    NSLog(@"dong");

    UIAlertView * asd = [[UIAlertView alloc]initWithTitle:@"sd" message:@"dfs" delegate:self cancelButtonTitle:@"dfdfs" otherButtonTitles:@"dsddsdff", nil];

    [asd show];

}

//搖動取消

- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event


{

    NSLog(@"ting");

}

//搖動結束

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    if (event.subtype == UIEventSubtypeMotionShake) {

        NSLog(@"tingle");

    }

}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章