ios摇一摇功能
//微信的搖一搖是怎么實現(xiàn)的~發(fā)現(xiàn)原來 ios本身就支持
//在 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);//這就是執(zhí)行搖一搖的方法。那么怎么用這些方法呢?//很簡單,你只需要讓這個Controller本身支持搖動//同時讓他成為第一相應(yīng)者:- (void)viewDidLoad{[superviewDidLoad];// Do any additional setup after loading the view, typically from a nib.
[[UIApplicationsharedApplication] setApplicationSupportsShakeToEdit:YES];[selfbecomeFirstResponder];}//然后去實現(xiàn)那幾個方法就可以了- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{//檢測到搖動
}- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{//搖動取消
}- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{//搖動結(jié)束if (event.subtype == UIEventSubtypeMotionShake) {//something happens
}}
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖
總結(jié)
- 上一篇: GDC dispatch_semapho
- 下一篇: ios关于相机访问权限设置