在新接手的项目上作开发是比较慢的,尤为是开发、产品、设计都换了几波人的上了年纪的项目。其实咱们仍是能够经过一些途径来提升维护老项目的效率。好比今天(全新的开发人员、产品、设计)就碰到设计说新作的需求有一个切图是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