swift学习笔记
2016-12-30 本文已影响0人
一点灬
1..取视频第一帧
- (void)movieToImage{
NSURL *url = self.playerView.videoURL;
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
AVAssetImageGeneratorCompletionHandler handler =
^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) { }//没成功
UIImage *thumbImg = [UIImage imageWithCGImage:im];
[self performSelectorOnMainThread:@selector(movieImage:) withObject:thumbImg waitUntilDone:YES];
};
generator.maximumSize = self.playerView.size;
[generator generateCGImagesAsynchronouslyForTimes:
[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
}
2..判断一个对象是否是某个类
if Vc.isKind(of: GLHomeTableViewController.self) {
return true
}
3..获取控件的最大值
CGRect.init().maxY
4..打包需要修改
70665009-32E6-4330-AF3B-29658BCF2D17.png5..归结档
var path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last! + "/user.data"
class GLAccountModel: NSObject {
//姓名
var name: String?
//构造函数
init(dic: [String: Any?]) {
super.init()
setValuesForKeys(dic)
}
//kvc赋值
override func setValue(_ value: Any?, forKey key: String) {
super.setValue(value, forKey: key)
}
//防止崩溃
override func setValue(_ value: Any?, forUndefinedKey key: String) {
}
required init?(coder aDecoder: NSCoder) {
super.init()
self.name = aDecoder.decodeObject(forKey: "name") as? String
}
func encode(with aCoder: NSCoder) {
aCoder.encode(self.name, forKey: "name")
}
class func save(user: GLAccountModel) -> Bool {
return NSKeyedArchiver.archiveRootObject(user, toFile: path)
}
class func account() -> GLAccountModel? {
return NSKeyedUnarchiver.unarchiveObject(withFile: path) as? GLAccountModel
}
}
6..Swift中 deinit 可以实现 “dealloc” 的功能
deinit {
println("没有循环引用")
}