激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - IOS - IOS開發實現手機震動的提示實例代碼

IOS開發實現手機震動的提示實例代碼

2021-03-13 16:26iOS開發網 IOS

這篇文章主要介紹了IOS開發實現手機震動的提示實例代碼的相關資料,需要的朋友可以參考下

ios開發實現手機震動的提示實例代碼

我們都知道手機有震動功能,其實呢,這個功能實現起來特別的簡單,我們只需要用到幾個函數就可以了: 

?
1
2
3
- (void)motionbegan:(uieventsubtype)motion withevent:(uievent *)event
- (void)motionended:(uieventsubtype)motion withevent:(uievent *)event
- (void)motioncancelled:(uieventsubtype)motion withevent:(uievent *)event

還有就是通過canbecomefirstresponder:設置一個第一響應者為label,然后搖動手機兩下,看看效果如下:

IOS開發實現手機震動的提示實例代碼

代碼如下:

hhlappdelegate.h

?
1
2
3
4
5
6
7
8
9
10
11
#import <uikit/uikit.h>
 
@class hhlviewcontroller;
 
@interface hhlappdelegate : uiresponder <uiapplicationdelegate>
 
@property (strong, nonatomic) uiwindow *window;
 
@property (strong, nonatomic) hhlviewcontroller *viewcontroller;
 
@end

hhlappdelegate.m

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#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

?
1
2
3
4
5
6
7
8
9
10
#import <uikit/uikit.h>
 
@interface hhlviewcontroller : uiviewcontroller
 
@end
 
 
@interface labelformotion : uilabel
 
@end

hhlviewcontroller.m

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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];
  //將標簽設置為第一響應者
  [label becomefirstresponder];
  [label release];
}
 
 
- (void)motionbegan:(uieventsubtype)motion withevent:(uievent *)event
{
  nslog(@"motionbegan");
}
 
//震動結束時調用的方法
- (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

其實更簡單的沒有必要搞一個類繼承自uilabel,可以直接定義一個uilabel的對象就行了。

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

原文鏈接:http://blog.csdn.net/hanhailong18/article/details/17615795

延伸 · 閱讀

精彩推薦
  • IOSiOS開發之視圖切換

    iOS開發之視圖切換

    在iOS開發中視圖的切換是很頻繁的,獨立的視圖應用在實際開發過程中并不常見,除非你的應用足夠簡單。在iOS開發中常用的視圖切換有三種,今天我們將...

    執著丶執念5282021-01-16
  • IOSiOS開發技巧之狀態欄字體顏色的設置方法

    iOS開發技巧之狀態欄字體顏色的設置方法

    有時候我們需要根據不同的背景修改狀態欄字體的顏色,下面這篇文章主要給大家介紹了關于iOS開發技巧之狀態欄字體顏色的設置方法,文中通過示例代碼...

    夢想家-mxj8922021-05-10
  • IOSiOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    這篇文章主要介紹了iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果的相關資料,需要的朋友可以參考下...

    jiangamh8882021-01-11
  • IOSiOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)

    iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和

    這篇文章主要介紹了iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)的相關資料,需要的朋友可以參考下...

    CodingFire13652021-02-26
  • IOS詳解iOS中多個網絡請求的同步問題總結

    詳解iOS中多個網絡請求的同步問題總結

    這篇文章主要介紹了詳解iOS中多個網絡請求的同步問題總結,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧...

    liang199111312021-03-15
  • IOSiOS中MD5加密算法的介紹和使用

    iOS中MD5加密算法的介紹和使用

    MD5加密是最常用的加密方法之一,是從一段字符串中通過相應特征生成一段32位的數字字母混合碼。對輸入信息生成唯一的128位散列值(32個字符)。這篇文...

    LYSNote5432021-02-04
  • IOSiOS中UILabel實現長按復制功能實例代碼

    iOS中UILabel實現長按復制功能實例代碼

    在iOS開發過程中,有時候會用到UILabel展示的內容,那么就設計到點擊UILabel復制它上面展示的內容的功能,也就是Label長按復制功能,下面這篇文章主要給大...

    devilx12792021-04-02
  • IOSiOS實現控制屏幕常亮不變暗的方法示例

    iOS實現控制屏幕常亮不變暗的方法示例

    最近在工作中遇到了要將iOS屏幕保持常亮的需求,所以下面這篇文章主要給大家介紹了關于利用iOS如何實現控制屏幕常亮不變暗的方法,文中給出了詳細的...

    隨風13332021-04-02
主站蜘蛛池模板: 欧美另类视频在线 | 激情宗合网 | 日韩大片在线永久观看视频网站免费 | 免费观看一区 | 麻豆一二区 | 爱逼爱操综合网 | 欧美一级黄色免费 | 最新在线中文字幕 | 嗯~啊~用力~高h | 国产日韩中文字幕 | 一级精品 | 欧美一级免费看 | 中国漂亮护士一级a毛片 | 欧美zoofilia杂交videos | 国产精品999在线观看 | 蜜桃精品视频 | 91精品国产九九九久久久亚洲 | 亚洲成人免费电影 | 最近免费观看高清韩国日本大全 | 久久精品国产99久久6动漫亮点 | 港台三级在线观看 | 成人午夜影院 | 小视频成人 | 久久精品视频黄色 | 超碰在线97国产 | 中国免费一级毛片 | 九九热精品在线播放 | 97中文 | 成人aaaaa片毛片按摩 | 中文字幕亚洲一区二区三区 | 美女福利视频国产 | 欧美一级特级 | 在线日韩av电影 | 最新在线黄色网址 | 91高清在线 | 国产精品一区二区视频 | 黄色午夜剧场 | 欧美一级成人 | 久久国产精品久久久久久久久久 | 久久亚洲春色中文字幕久久 | 日韩在线激情 |