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..打包需要修改
5..歸結(jié)檔
var path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last! + "/user.data"
class GLAccountModel: NSObject {
//姓名
var name: String?
//構(gòu)造函數(shù)
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 可以實(shí)現(xiàn) “dealloc” 的功能
deinit {
println("沒有循環(huán)引用")
}