苹果手机怎么关震动实现手机震动

匿名用户不能发表回复!|IOS简单的实现手机震动的提示
我们都知道手机有震动功能,其实呢,这个功能实现起来特别的简单,我们只需要用到几个函数就可以了:
- (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
vcD4KPHByZSBjbGFzcz0="brush:">#import
@class HHLViewC
@interface HHLAppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *
@property (strong, nonatomic) HHLViewController *viewC
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.viewC
[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 t 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:.
HHLViewController.h
@interface HHLViewController : UIViewController
@interface LabelForMotion : UILabel
HHLViewController.m
#import "HHLViewController.h"
@interface HHLViewController ()
@implementation LabelForMotion
- (BOOL)canBecomeFirstResponder
return YES;
@implementation HHLViewController
- (void)viewDidLoad
[super viewDidLoad];
LabelForMotion *label = [[[LabelForMotion alloc]init]autorelease];
label.frame = self.view.
label.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleH
label.textAlignment = NSTextAlignmentC
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];
[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.
其实更简单的没有必要搞一个类继承自UIlabel,可以直接定义一个UIlabel的对象就行了。21ic官方微信-->
> 用了15年手机 终于知道震动如何实现了
用了15年手机 终于知道震动如何实现了(1/12)
发布时间:
09:40:31&&阅读数: 2350&&点赞数: 3
&&支持键翻动图片
手机震动功能早在功能机时代就有了,震动是一个看起来很小但是不可或缺的功能,尤其是在某些公共场所,手机静音之后震动成为了手机提醒我们的唯一方式。
已经浏览完本图集,你可能感兴趣
成功上传了个图集
用了15年手机 终于知道震动如何实现了
常用软件下载
热门资料下载
一周浏览排行榜
北京时间2月25日晚21:00,华为在西班牙巴塞罗那召开了2018年第一行新品发布会,在会中华为发布了两款笔记本电脑外还发布了全新的MediaPad M5平板电脑,其中M5系列平板电脑分为8.4英寸和10.8英寸,此外还有一款重量级平板电脑MediaPad M5 Pro,并且配备了手写笔。下面我们就来抢先看一下这三款平板电脑现场图上吧。
神秘波音飞机被弃巴厘岛 引众多游客前往参观
昨日,vivo一款概念机秒杀MWC2018全场,瞬间洗刷了网友对vivo品牌的认知,各路粉丝纷纷表示化身V粉,为vivo概念机打Call。
这就是vivo APEX,尤其是它那高达98%的屏占比,极具视觉冲击力,很多人看到它都啧啧称奇,堪称完美。APEX的出现迅速在网络上引发一片热烈讨论,遮盖了MWC2018上机皇们头顶的光芒。
YOTA3拆解首发 让双屏设计更趋完美
三星S9&iPhoneX面对面开怼 这仗忒刺激了
在MWC 2018上,中兴发布了旗下新机Blade V9,这部手机将主打暗光双摄和全面屏设计,并且定位年轻人群和摄影爱好者。中兴Blade V9系列将登陆西班牙、德国、俄罗斯、墨西哥和中国等大国市场,售价269欧元起。
华为P20 Plus带壳渲染图曝光:后置三摄+正面指纹
印度爆发20万人大规模集会

我要回帖

更多关于 苹果手机怎么关闭震动 的文章

 

随机推荐