我們都知道手機有震動功能,其實呢,這個功能實現起來特別的簡單,我們只需要用到幾個函式就可以了:
- (void)motionbegan:(uieventsubtype)motion withevent:(uievent *)event
- (void)motionended:(uieventsubtype)motion withevent:(uievent *)event
- (void)motioncancelled:(uieventsubtype)motion withevent:(uievent *)event
還有就是通過canbecomefirstresponder:設定乙個第一響應者為label,然後搖動手機兩下,看看效果如下:
**如下:
hhlappdelegate.h
#import
@class hhlviewcontroller;
@inte***ce hhlappdelegate : uiresponder
@property (strong, nonatomic) uiwindow *window;
@property (strong, nonatomic) hhlviewcontroller *viewcontroller;
@end
hhlappdelegate.m
#import "hhlappdelegate.h"
#import "hhlviewcontroller.h"
@implementation hhlappdelegate
- (void)dealloc
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions
- (void)applicationwillresignactive:(uiapplication *)application
- (void)applicationdidenterbackground:(uiapplication *)application
- (void)applicationwillenterforeground:(uiapplication *)application
- (void)applicationdidbecomeactive:(uiapplication *)application
- (void)applicationwillterminate:(uiapplication *)application
@end
hhlviewcontroller.h
#import
@inte***ce hhlviewcontroller : uiviewcontroller
@end
@inte***ce labelformotion : uilabel
@end
hhlviewcontroller.m
#import "hhlviewcontroller.h"
@inte***ce hhlviewcontroller ()
@end
@implementation labelformotion
- (bool)canbecomefirstresponder
@end
@implementation hhlviewcontroller
- (void)viewdidload
- (void)motionbegan:(uieventsubtype)motion withevent:(uievent *)event
//震動結束時呼叫的方法
- (void)motionended:(uieventsubtype)motion withevent:(uievent *)event
- (void)motioncancelled:(uieventsubtype)motion withevent:(uievent *)event
- (void)didreceivememorywarning
@end
其實更簡單的沒有必要搞乙個類繼承自uilabel,可以直接定義乙個uilabel的物件就行了。
android 震動的實現
通過震動的整體實現來理解驅動的開發 一 應用層 android的系統有乙個專門處理震動請求的服務,通過它應用就能夠向系統請求多長時間的震動 vibrator vib vibrator activity.getsystemservice service.vibrator service vib.vib...
Android學習之震動你的手機
因為在寫遊戲的過程中用到震動手機的知識,特和大家分享一下。第一步 宣告程式許可權 第二步 獲取vibrator物件 vibrator vibrator vibrator getsystemservice context.vibrator service 有點像獲取感測器sensor吧。第三步 宣告l...
PHP的簡單跳轉提示的實現
在php開發中,尤其是mvc框架或者專案中,會碰到很多跳轉情況,比如 登入成功或失敗後的跳轉等等。以下以mvc框架開發中為基礎,示例講解 在基礎控制器類中 conrtoller.class.php 1 4 基礎控制器類5 6class controller else53 5455 在mvc的自動載入...