iOS 杂烩

来源:互联网 发布:大宗商品价格数据 编辑:程序博客网 时间:2024/05/01 10:53

2计算某个日期距离今天多少天

NSDate * newDate = [Tool stringToDate:newDateStr];

HaventDown07Count = (int)[self calcDaysFromBegin:newDate end:[NSDate date]];//计算两个日期之间的天数

-(NSInteger) calcDaysFromBegin:(NSDate *)inBegin end:(NSDate *)inEnd

{

    NSInteger unitFlags = NSDayCalendarUnit| NSMonthCalendarUnit | NSYearCalendarUnit;

    NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *comps = [cal components:unitFlags fromDate:inBegin];

    NSDate *newBegin  = [cal dateFromComponents:comps];

    

    

    NSCalendar *cal2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *comps2 = [cal2 components:unitFlags fromDate:inEnd];

    NSDate *newEnd  = [cal2 dateFromComponents:comps2];

    

    

    NSTimeInterval interval = [newEnd timeIntervalSinceDate:newBegin];

    NSInteger beginDays=((NSInteger)interval)/(3600*24);

    

    return beginDays;

}



2结束app需要两次才能彻底结束的解决办法

 蓝牙连接的时候结束app,发现要在后台结束两次才能彻底结束,解决的办法是在appdelegate- (void)applicationWillTerminate:(UIApplication *)application方法里面,去断开蓝牙连接,就正常了




2据说可以正确取得宽高

[[UIScreen mainScreen]bounds].size.width

//http://www.cocoachina.com/bbs/read.php?tid-264373.html





2开始跑步view向外扩散的动画

只需计算view放大到最大后的位置就行

float height = [[UIScreen mainScreen] bounds].size.height;

    float width = [[UIScreen mainScreen] bounds].size.width;


    [UIView beginAnimations:nil context:nil];// 开始动画

    [UIView setAnimationDuration:2.0]; // 动画时长

    [UIView setAnimationRepeatCount:666];


    //动画的内容

    CGSize size = _TransformView.frame.size;

    size.height = size.height*1.55;

    size.width = size.width*1.55;

    CGRect frame = _TransformView.frame;

    frame.size = size;

    frame.origin = CGPointMake(width/2-size.width/2, height/2-size.height/2);

    _TransformView.frame = frame;

    

    _TransformView.alpha = 0.0;

    

    [UIView commitAnimations]; // 提交动画




2蓝牙的各种系统key

- (id)initWithDelegate:(id<CBCentralManagerDelegate>)delegate queue:(dispatch_queue_t)queue options:(NSDictionary *)options

方法说明:delegate代理:接受中心事件        queue:指明在哪个队列处理事件,为nil时表示在主线程处理

options:有一下两个选择

NSString *const CBCentralManagerOptionShowPowerAlertKey;用该参量出事中央管理器时,当蓝牙开关未打开时会弹出警告框。

NSString *const CBCentralManagerOptionRestoreIdentifierKey;该参量包含一个指定中央管理器的uid

http://blog.csdn.net/feixiang_song/article/details/17395811


CBConnectPeripheralOptionNotifyOnConnectionKey:这是一个NSNumber(Boolean),表示系统会为获得的外设显示一个提示,当成功连接后这个应用被挂起,这对于没有运行在中心后台模式并不显示他们自己的提示时是有用的。如果有更多的外设连接后都会发送通知,如果附近的外设运行在前台则会收到这个提示。

CBConnectPeripheralOptionNotifyOnDisconnectionKey:  这是一个NSNumber(Boolean), 表示系统会为获得的外设显示一个关闭提示,如果这个时候关闭了连接,这个应用会挂起。

CBConnectPeripheralOptionNotifyOnNotificationKey: 这是一个NSNumber(Boolean),表示系统会为获得的外设收到通知后显示一个提示,这个时候应用是被挂起的。

http://www.cnblogs.com/flylovesky/p/3274869.html

[self.manager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES, CBConnectPeripheralOptionNotifyOnDisconnectionKey:@YES, CBConnectPeripheralOptionNotifyOnNotificationKey:@YES}];




2蓝牙后台情况实测

自己实测的情况是app在后台断线后,蓝牙会自动连接,手环发给app的数据也可以收到,控制台打印出来了,然后app也可以做相应的事情,比如断线后报警,即使app在后台超过十分钟以后仍旧可以做这些事情。有可能是勾选了后台激活播放无声音乐的三个选项导致!(虽然勾选了这三个选项,但是并没有执行阻止睡眠和停止阻止睡眠那两个方法)。之后的实测证实了是勾选了这三个选项之后才可以做到以上这样的!因为我在工程中勾选和不勾选这两种情况都做了测试,证实了这个结论的。不勾选的时候控制台一片空白,不执行任何代码,勾选了则相反。但是,我在appdelegate中每秒打印监听通话的变量,在前台时可以打印,一旦退到后台,就不执行了,貌似只有蓝牙相关的api可以执行。使用CoreTelephony这个库监听通话,在后台无法监听到,并没有执行回调方法。





2没有在主线程刷新UI

This application is modifying the autolayout engine from a background thread, which can lead to engi





2某一年某一月的天数

int HowManyDayInThisMonth = [SingleTonManager howManyDaysInThisMonth:year+2000 month:month];






2拿到今天的年月日

NSDate *nowDate = [NSDate date];

        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSDateComponents *comp = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSDayCalendarUnit fromDate:nowDate];

        year = (int)[comp year]-2000;

        month = (int)[comp month];

        // 获取几天是几号

        day = (int)[comp day];




2屏幕取色方法 

http://jingyan.baidu.com/article/e9fb46e1731e777520f7666e.html




2前往设置里的蓝牙

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];

 结合下面链接介绍的方法即可:

 http://www.jianshu.com/p/19602f48309b




2取得当前的年月日,非弃用的属性

NSDate *nowDate = [NSDate date];

        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSDateComponents *comp = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:nowDate];

        // 获取今天是周几

        NSInteger weekDay = [comp weekday];

        // 获取几天是几号

        NSInteger day = [comp day];






2取得某个制定indexpath的cell

NSIndexPath *path=[NSIndexPath indexPathForRow:i inSection:0];

            PeripheralCell *cell = [TableView cellForRowAtIndexPath:path];

            cell.backgroundColor = [UIColor colorWithRed:73.0/255.0 green:200.0/255.0 blue:199.0/255.0 alpha:1.0];




2取得数组中最大值和最小值

[HeartRate48ItemArray addObjectsFromArray:FourthArray];


            int BiggestValue = 0;

            int SmallestValue = 0;

            

            for (int i =0; i < HeartRate48ItemArray.count; i ++) {

                //取出第一个值

                BiggestValue = [HeartRate48ItemArray[0] intValue];

                SmallestValue = [HeartRate48ItemArray[0] intValue];

                //删掉第一个

                [HeartRate48ItemArray removeObject:HeartRate48ItemArray[0]];

                

                for (int j =0; j<HeartRate48ItemArray.count;) {

                   //取出原来的第二个;循环第二次的时候,取出第三个

                    NSString *firstItem = HeartRate48ItemArray[0];

                    int CurrentValue = [firstItem intValue];

                    [HeartRate48ItemArray removeObject:firstItem];

                    //判断哪个值大,大的赋值给biggestvalue

                    if (CurrentValue>=BiggestValue) {

                        BiggestValue = CurrentValue;

                    }

                    if (CurrentValue<=SmallestValue) {

                        SmallestValue = CurrentValue;

                    }

                }

            }

            LOG(@"最大值 == %d",BiggestValue);

            LOG(@"最小值 == %d",SmallestValue);






2取一个数组中最大的值

NSMutableArray *valuesArr = [[NSMutableArray alloc]initWithArray:@[@"18",@"15",@"1",@"2",@"16",@"3",@"4",@"5",@"15",@"6",@"7",@"8",@"17",@"9",@"10",@"11",@"19"]];

    

    int BiggestValue = 0;

    

    for (int i =0; i < valuesArr.count; i ++) {

        //取出第一个值

        BiggestValue = [valuesArr[0] intValue];

        //删掉第一个

        [valuesArr removeObject:valuesArr[0]];

        

        for (int j =0; j<valuesArr.count;) {

           //取出原来的第二个;循环第二次的时候,取出第三个

            NSString *firstItem = valuesArr[0];

            int CurrentValue = [firstItem intValue];

            [valuesArr removeObject:firstItem];

            //判断哪个值大,大的赋值给biggestvalue

            if (CurrentValue>=BiggestValue) {

                BiggestValue = CurrentValue;

                

               

            }

        }

    }

    NSLog(@"最大值 == %d",BiggestValue);





2去除系统总是弹窗提示打开蓝牙

_manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{CBCentralManagerOptionShowPowerAlertKey:@YES}];






2让数组内的元素都调用某个方法

[[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];



0 0
原创粉丝点击