一些不常用的方法

忽略警告

忽略可能存在内存泄漏警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
          [moduleInstance performSelector:selector
                               withObject:[UPContext sharedInstance]];
#pragma clang diagnostic pop
      }
支持http协议

ios9开始苹果安全会自动先知http网址的访问,如果想开放此访问,需要在info.plist中进行修改。
添加App Transport Security Setting,其中继续添加Allow Arbitrary Loads,设置为Yes

宏定义中"##","@#"

例如DKNightVersionManager中宏定义语法
#define DKColorPickerWithKey(key) [[DKColorTable sharedColorTable] pickerWithKey:@#key]
使用时:
self.dk_backgroundColorPicker = DKColorPickerWithKey(backgroundColor);
backgroundColor本身不是字符串,可在宏定义中经过@#字符,其中#为字符串化的意思,转换为@"backgroundColor"字符串。
此为C中语法。
可参考如下:

#define f(a,b) a##b             //##被称为连接符(concatenation),把宏参数与之前的token(参数/字符串空格等)连接起来。
#define g(a) #a                 //#:把宏参数转换为字符串。不管该参数宏什么,即“原貌”用字符串显示出来
音频后台播放
// Apps using this category don't mute when the phone's mute button is turned on, but play sound when the phone is silent
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
渐变色
    CAGradientLayer *graLayer = [CAGradientLayer layer];
    graLayer.frame = CGRectMake(100, 100, 200, 200);
    graLayer.colors = @[
        (__bridge id)[UIColor redColor].CGColor,
        (__bridge id)[UIColor yellowColor].CGColor
    ];
//    graLayer.locations = @[@0, @0.2];
    graLayer.startPoint = CGPointMake(0, 0);
    graLayer.endPoint = CGPointMake(1, 1);
    [self.view.layer addSublayer:graLayer];
旋转适配
- (void)viewSafeAreaInsetsDidChange{
    [super viewSafeAreaInsetsDidChange];
    
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
    if (@available(iOS 11.0, *)){
           
        if (deviceOrientationisLandscape()) {
            [self.commentMoreBtn mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(self.view.mas_safeAreaLayoutGuideRight).offset(-15);
            }];
        }else
        {
            [self.commentMoreBtn mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-15);
            }];
        }
    }
#endif
}
系统下拉手势冲突问题
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
    return UIRectEdgeAll;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容