开发过程中小的知识点梳理(四)

1.presentViewController显示方式的窗口,没有导航栏的解决方法

InvitationViewController *invitation = [[InvitationViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:invitation];
[self.selectedViewController presentViewController:nav animated:YES completion:nil];

2.应用内打开或跳转另一个APP(URL Scheme与openURL)

//1.无需添加白名单
NSURL *url = [NSURL URLWithString:@"weixin://"];   //@"weixin://"是微信的URL Scheme
[[UIApplication sharedApplication] openURL:url];

//2.必须添加白名单
if ([[UIApplication sharedApplication] canOpenURL:@"weixin://"]) {
        //打开url
        [[UIApplication sharedApplication] openURL:@"weixin://"];
    }

//这里必须要把weixin加入白名单,才可以通过canOpenURL的判断,进而跳转到微信

//备注:白名单只是对canOpenURL:方法有限制,openURL:方法是没有限制的。

//添加白名单的方法:
步骤:点击info.plist->右键->Open As->Source Code->添加下面的代码

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>weixin</string>
    </array>

3.UIColor数组的使用

#import "ViewController.h"

@interface ViewController (){


    UIColor *_color[5];
    NSTimer *_timer;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _color[0] = [UIColor redColor];
    _color[1] = [UIColor blueColor];
    _color[2] = [UIColor greenColor];
    _color[3] = [UIColor cyanColor];
    _color[4] = [UIColor yellowColor];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(change) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
}

- (void)delloc {
    [self.timer invalidate];
}
- (void)change{

    int x = arc4random() % 5;
    self.view.backgroundColor = _color[x];
}
@end

4.使用距离传感器(靠近/远离屏幕-变暗/变亮)

#import "ScreenDistanceViewController.h"
#import "ScreenDefaultTipView.h"

@interface ScreenDistanceViewController ()
@property (nonatomic, strong) ScreenDefaultTipView *defaultTipsView;
@property (nonatomic) BOOL  isNear; //靠近
@property (nonatomic) BOOL  isRemoved; //远离
@end

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"屏幕距离感应";

    //1.开启距离传感器
    [UIDevice currentDevice].proximityMonitoringEnabled = YES;

    // 2.传感器状态发生变化时发送通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityState:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)closeProximity {
    //关闭距离传感器
    [UIDevice currentDevice].proximityMonitoringEnabled = NO;
}


- (void)proximityState:(NSNotificationCenter *)notification {

    if ([[UIDevice currentDevice] proximityState] == YES) {
        self.isNear = YES;
    }else {
        self.isRemoved = YES;
    }

    if (self.isNear && self.isRemoved) {
        self.defaultTipsView.hidden = NO;
        [_defaultTipsView image:[UIImage imageNamed:@"device_helpcheck_ok"] title:@"检测正常" description:@"距离感应器感应正常"];
        [self closeProximity];
    }else if (!self.isNear && !self.isRemoved){
        self.defaultTipsView.hidden = NO;
        [_defaultTipsView image:[UIImage imageNamed:@"device_helpcheck_error"] title:@"检测异常" description:@"距离感应器感应异常"];
        [self closeProximity];
    }

}

4.沿X轴左右来回平移动画

- (void)moveImageAnimation{
    // x轴方向平移
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    //延迟1秒执行
    animation.beginTime = CACurrentMediaTime() + 1;  
    //持续时间
    animation.duration = 1.5;
    //重复次数
    animation.repeatCount = INT_MAX;
    //开启重复执行
    animation.autoreverses = YES; 
    //平移距离
    animation.toValue = @(-100);
    // 添加动画
    [self.handImage.layer addAnimation:animation forKey:@"move"];
}

参考链接:https://blog.csdn.net/liuq0725/article/details/78615077

5.UIAlertController里message属性的修改


NSString *titleString = @"火箭手机管家版本更新文案";  
NSString *messageString = @"更新内容:
1、新增硬件检测功能,新机、二手机买卖好帮手,妈妈再也不怕我买到有故障的手机了;
2、优化隐私空间、照片清理界面,提高页面友好度;
3、完美适配iPhone X;
4、把小伙伴们反馈的bug都修复了。"; 

UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleString message:messageString preferredStyle:UIAlertControllerStyleAlert];
        //修改message
        NSMutableAttributedString *attMsgString = [[NSMutableAttributedString alloc] initWithString:model.content];
        [attMsgString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, attMsgString.length)];
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        [paragraph setLineSpacing:3];   //行间距
        [paragraph setParagraphSpacingBefore:5];  //段间距
        [paragraph setAlignment:NSTextAlignmentLeft];   //左对齐
        [paragraph setBaseWritingDirection:NSWritingDirectionLeftToRight];
        [attMsgString addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, attMsgString.length)];
        [alert setValue:attMsgString forKey:@"attributedMessage"];

        [alert addAction:[UIAlertAction actionWithTitle:@"暂不更新" style:UIAlertActionStyleDefault handler:nil]];
        [alert addAction:[UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.url]];
        [self presentViewController:alert animated:YES completion:nil];

修改后:
这里写图片描述

参考链接:https://blog.csdn.net/wsyx768/article/details/60874420

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值