资料
1.重写NSLog
#ifdef DEBUG //调试状态,打开LOG功能
#define ZYLog(...) NSLog(__VA_ARGS__)
#else //发布状态。关闭log功能
#define ZYLog(...)
#endif
2.设置选中的图标
UIImage *selectedImage = [UIImage imageWithName:selectedImageName];
// 声明这张图片用原图(别渲染)
selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
childVc.tabBarItem.selectedImage = selectedImage;
// 添加为tabbar控制器的子控制器
[self addChildViewController:childVc];
3.HTTP
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
4.定时器
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
5.图片居中
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight __TVOS_PROHIBITED;
6.版本新特性
NSString *versionKey = (__bridge NSString *)kCFBundleVersionKey;
NSString *version = [NSBundle mainBundle].infoDictionary[versionKey];
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
if ([[userDefault objectForKey:versionKey] isEqualToString:version]) {
self.window.rootViewController = [[ViewController alloc] init];
} else {
self.window.rootViewController = [[NewFeatureViewController alloc] init];
[userDefault setObject:version forKey:versionKey];
}
// 显示主控制器(HMTabBarController)
HMTabBarViewController *vc = [[HMTabBarViewController alloc] init];
// 切换控制器
UIWindow *window = [UIApplication sharedApplication].keyWindow;
window.rootViewController = vc;
// push : [self.navigationController pushViewController:vc animated:NO];//内存问题
// modal : [self presentViewController:vc animated:NO completion:nil];//内存问题
// window.rootViewController : window.rootViewController = vc;
7.AVPlayerViewController
@property (nonatomic, strong) AVPlayer *player;
@property (nonatomic, strong) AVPlayerViewController *playerView;
实现代码
NSString *playString = @"http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4";
//视频播放的url
NSURL *playerURL = [NSURL URLWithString:playString];
//初始化
self.playerView = [[AVPlayerViewController alloc]init];
//AVPlayerItem 视频的一些信息 创建AVPlayer使用的
AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:playerURL];
//通过AVPlayerItem创建AVPlayer
self.player = [[AVPlayer alloc]initWithPlayerItem:item];
//给AVPlayer一个播放的layer层
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
layer.frame = CGRectMake(0, 100, self.view.frame.size.width, 200);
layer.backgroundColor = [UIColor greenColor].CGColor;
//设置AVPlayer的填充模式
layer.videoGravity = AVLayerVideoGravityResize;
[self.view.layer addSublayer:layer];
//设置AVPlayerViewController内部的AVPlayer为刚创建的AVPlayer
self.playerView.player = self.player;
//关闭AVPlayerViewController内部的约束
self.playerView.view.translatesAutoresizingMaskIntoConstraints = YES;
点击播放
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self showViewController:self.playerView sender:nil];
}
8.coreData
NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSMigratePersistentStoresAutomaticallyOption: @YES} error:&error
9.KVO观察机制
//KVO观察机制
/*
调用者:被观察的对象
参数1.观察的对象
参数2.观察的属性
参数3.观察的选项(观察新旧值)
参数4.传递给回调函数的参数
*/
[self.bank addObserver:self forKeyPath:@"money" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
//一旦观察的属性发生变化,就会回调以下方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
// keyPath观察的属性
// object被观察的对象
// change观察的信息
// context传递过来的参数