zoukankan      html  css  js  c++  java
  • FirstApp,iphone开发学习总结13,方向感应和通告

    方向感应:

    在ImageViewController.h中添加UIAccelerometerDelegate:

    @interface ImageViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIAccelerometerDelegate>{
    //...

    ImageViewController.m文件内,初始化UIAccelerometer,在viewWillAppear:animated中:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        UIAccelerometer *acc = [UIAccelerometer sharedAccelerometer];
        [acc setUpdateInterval:0.1];//0.1s
        [acc setDelegate:self];
    }

    当view被移除,需要释放:

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
    }

    实现委托:

    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
    {
        NSLog(@"x:%f, y:%f, z:%f", [acceleration x], [acceleration y], [acceleration z]);
        //[self setNeedsDisplay];//可以刷新view
    }

    通告部分:

        //接受通告
        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
        [nc addObserver:self selector:@selector(nc:) name:@"a" object:nil];
        
        //创建通告
        NSDictionary *info =[NSDictionary dictionary];
        NSNotification *note = [NSNotification notificationWithName:@"a" object:self userInfo:info];
        [[NSNotificationCenter defaultCenter] postNotification:note];
  • 相关阅读:
    111
    使用正则表达式,取得点击次数,函数抽离
    爬虫大作业
    Hadoop综合大作业
    hive基本操作与应用
    熟悉HBase基本操作
    爬虫大作业
    第三章 熟悉常用的HDFS操作
    数据结构化与保存
    用正则表达式,取得点击次数,函数抽离
  • 原文地址:https://www.cnblogs.com/maxfong/p/2503412.html
Copyright © 2011-2022 走看看