在新接手的項目上作開發是比較慢的,尤爲是開發、產品、設計都換了幾波人的上了年紀的項目。其實咱們仍是能夠經過一些途徑來提升維護老項目的效率。好比今天(全新的開發人員、產品、設計)就碰到設計說新作的需求有一個切圖是app中原來就有的,爲了保持風格統一,沿用原來的切圖。難道還須要定位到當前的頁面對應的代碼中去尋找相應圖片的名字嗎?若是後面的新需求有大量相似的圖片怎麼辦?通過一番思考,肯定了一種比較快速定位圖片名字的方法。以下:html
利用runtime
在UIImage
的分類中給UIImage
關聯一個屬性p_name
,替換原來的imageNamed:
方法,在本身的方法中將圖片的名字保存到p_name
中。ios
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIImage (name)
@end
NS_ASSUME_NONNULL_END
複製代碼
#import "UIImage+name.h"
#import <objc/runtime.h>
@implementation UIImage (name)
- (void)setP_name:(NSString *)p_name {
objc_setAssociatedObject(self, @selector(p_name), p_name, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)p_name {
return objc_getAssociatedObject(self, _cmd);
}
+ (UIImage *)wsk_imageNamed:(NSString *)imageName {
UIImage *image = [UIImage wsk_imageNamed:imageName];
image.p_name = imageName;
return image;
}
+(void)load {
Method imageNameMethod = class_getClassMethod([self class], @selector(imageNamed:));
Method wsk_imageNamedMethod = class_getClassMethod([UIImage class], @selector(wsk_imageNamed:));
method_exchangeImplementations(imageNameMethod, wsk_imageNamedMethod);
}
@end
複製代碼
- 方法一:不借助任何外部工具,使用
xcode
的Debug View Hierarchy
- 方法二:使用Chisel命令
pviews
。
- 方法三:使用工具FLEX找到
UIImageVIew
的地址。
使用LLDB
的po
命令 po [((UIImageView*)0x122203f40).image valueForKey:@"p_name"]
打印圖片的名字。git
注意:
xib
中設置的圖片名字,打印爲nil
github
視頻轉GIF步驟xcode
- 一、
brew install ffmpeg
- 二、
ffmpeg -ss 00:00:00 -i flex.mov -s 375x667 -r "2" flex.gif