欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS開發(fā)實(shí)現(xiàn)手機(jī)震動(dòng)的提示實(shí)例代碼

 更新時(shí)間:2017年04月13日 14:12:58   投稿:lqh  
這篇文章主要介紹了IOS開發(fā)實(shí)現(xiàn)手機(jī)震動(dòng)的提示實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下

IOS開發(fā)實(shí)現(xiàn)手機(jī)震動(dòng)的提示實(shí)例代碼

我們都知道手機(jī)有震動(dòng)功能,其實(shí)呢,這個(gè)功能實(shí)現(xiàn)起來特別的簡單,我們只需要用到幾個(gè)函數(shù)就可以了: 

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

還有就是通過canBecomeFirstResponder:設(shè)置一個(gè)第一響應(yīng)者為label,然后搖動(dòng)手機(jī)兩下,看看效果如下:

代碼如下:

HHLAppDelegate.h

#import <UIKit/UIKit.h> 
 
@class HHLViewController; 
 
@interface HHLAppDelegate : UIResponder <UIApplicationDelegate> 
 
@property (strong, nonatomic) UIWindow *window; 
 
@property (strong, nonatomic) HHLViewController *viewController; 
 
@end 

HHLAppDelegate.m

#import "HHLAppDelegate.h" 
 
#import "HHLViewController.h" 
 
@implementation HHLAppDelegate 
 
- (void)dealloc 
{ 
  [_window release]; 
  [_viewController release]; 
  [super dealloc]; 
} 
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
  self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
  // Override point for customization after application launch. 
  self.viewController = [[[HHLViewController alloc] initWithNibName:@"HHLViewController" bundle:nil] autorelease]; 
  self.window.rootViewController = self.viewController; 
  [self.window makeKeyAndVisible]; 
  return YES; 
} 
 
- (void)applicationWillResignActive:(UIApplication *)application 
{ 
  // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
  // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
} 
 
- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
  // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.  
  // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 
 
- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
  // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
} 
 
- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
  // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 
 
- (void)applicationWillTerminate:(UIApplication *)application 
{ 
  // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 
 
@end 

HHLViewController.h

#import <UIKit/UIKit.h> 
 
@interface HHLViewController : UIViewController 
 
@end 
 
 
@interface LabelForMotion : UILabel 
 
@end 

HHLViewController.m

#import "HHLViewController.h" 
 
@interface HHLViewController () 
 
@end 
 
 
 
@implementation LabelForMotion 
 
- (BOOL)canBecomeFirstResponder 
{ 
  return YES; 
} 
 
@end 
@implementation HHLViewController 
 
- (void)viewDidLoad 
{ 
  [super viewDidLoad]; 
  LabelForMotion *label = [[[LabelForMotion alloc]init]autorelease]; 
  label.frame = self.view.bounds; 
  label.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 
  label.textAlignment = NSTextAlignmentCenter; 
   
  label.text = @"Shake me"; 
  [self.view addSubview:label]; 
  //將標(biāo)簽設(shè)置為第一響應(yīng)者 
  [label becomeFirstResponder]; 
  [label release]; 
} 
 
 
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{ 
  NSLog(@"motionBegan"); 
} 
 
//震動(dòng)結(jié)束時(shí)調(diào)用的方法 
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{ 
  NSLog(@"motionEnded"); 
  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"地震了" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil nil]; 
  [alert show]; 
  [alert release]; 
   
} 
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{ 
  NSLog(@"motionCancelled"); 
} 
 
 
- (void)didReceiveMemoryWarning 
{ 
  [super didReceiveMemoryWarning]; 
  // Dispose of any resources that can be recreated. 
} 
 
@end 

其實(shí)更簡單的沒有必要搞一個(gè)類繼承自UIlabel,可以直接定義一個(gè)UIlabel的對象就行了。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • iOS自定義身份證鍵盤

    iOS自定義身份證鍵盤

    這篇文章主要為大家詳細(xì)介紹了iOS自定義身份證鍵盤,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • iOS實(shí)時(shí)監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變

    iOS實(shí)時(shí)監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)時(shí)監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-08-08
  • 詳解iOS視頻播放方式

    詳解iOS視頻播放方式

    本篇文章給大家詳細(xì)講述了詳解iOS視頻播放方式以及第三方開元播放軟件的使用,學(xué)習(xí)下吧。
    2017-12-12
  • iOS開發(fā)之?dāng)r截URL轉(zhuǎn)換成本地路由模塊URLRewrite詳解

    iOS開發(fā)之?dāng)r截URL轉(zhuǎn)換成本地路由模塊URLRewrite詳解

    這篇文章主要給大家介紹了關(guān)于iOS開發(fā)之?dāng)r截URL轉(zhuǎn)換成本地路由模塊URLRewrite的相關(guān)資料,這是最近在工作中遇到的一個(gè)需求,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起看看吧。
    2017-08-08
  • iOS開發(fā)--仿新聞首頁效果WMPageController的使用詳解

    iOS開發(fā)--仿新聞首頁效果WMPageController的使用詳解

    這篇文章主要介紹了iOS開發(fā)--仿新聞首頁效果WMPageController的使用詳解,詳解的介紹了iOS開發(fā)中第三方庫WMPageController控件的使用方法,有需要的可以了解下。
    2016-11-11
  • IOS數(shù)字鍵盤左下角添加完成按鈕的實(shí)現(xiàn)方法

    IOS數(shù)字鍵盤左下角添加完成按鈕的實(shí)現(xiàn)方法

    這篇文章主要介紹了IOS數(shù)字鍵盤左下角添加完成按鈕的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能實(shí)現(xiàn)類似這樣的功能,需要的朋友可以參考下
    2017-08-08
  • H5混合開發(fā)IOS中遇到的坑

    H5混合開發(fā)IOS中遇到的坑

    本篇文章主要給大家講述了在用H5混合開發(fā)APP時(shí),IOS項(xiàng)目中遇到的坑以及解決辦法,需要的朋友參考一下吧。
    2017-12-12
  • 最新評論