iOS开发基础知识--碎片43
Posted 李洪强
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发基础知识--碎片43相关的知识,希望对你有一定的参考价值。
ios开发基础知识--碎片43
1:增加手势进行左划效果,针对视图并修改其中一个的坐标,菜单用隐藏跟显示
@property(strong,nonatomic)UISwipeGestureRecognizer *recognizer;
self.recognizer = [[ UISwipeGestureRecognizer alloc ] initWithTarget:self action:@selector (handleSwipeFrom:)]; [self.recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; [self addGestureRecognizer :self.recognizer];
- (void)handleSwipeFrom:( UISwipeGestureRecognizer *)sender{if (sender.direction == UISwipeGestureRecognizerDirectionLeft ) { self.rightButton.hidden=NO; [self.recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; [self.valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.rightButton.left).with.offset(-5); make.centerY.mas_equalTo(self).with.offset(0); make.size.mas_equalTo(CGSizeMake(Main_Screen_Width-180, 15)); }]; [self.valueLabel layoutIfNeeded]; } else { self.rightButton.hidden=YES; [self.recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; [self.valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.right).with.offset(-15); make.centerY.mas_equalTo(self).with.offset(0); make.size.mas_equalTo(CGSizeMake(Main_Screen_Width-180, 15)); }]; [self.valueLabel layoutIfNeeded]; } }
2:属性名以new开头解决方式
@property (nonatomic,copy) NSString *new_Passwd;
像上面这样写法会报错,可以替换成
@property (nonatomic,copy,getter = theNewPasswd) NSString *new_Passwd;
3:单例类一些注意事项
如果allocWithZone里面的代码不写,用以下三种创建的实例还是三种,不符合我们对单例的运用,当然如果你只针对[HLTestObject sharedInstance]进行实例化时,就是一直满足;把初始化的属性对象放在sharedInstance里面,如果放在init里面进行初始化也会出现不一样的情景;
HLTestObject *objct1 = [HLTestObject sharedInstance]; NSLog(@"%@",objct1); HLTestObject *objc2 = [[HLTestObject alloc] init]; NSLog(@"%@",objc2); HLTestObject *objc3 = [HLTestObject new]; NSLog(@"%@",objc3);
声明属性:
@property (assign, nonatomic) int height; @property (strong, nonatomic) NSObject *object; @property (strong, nonatomic) NSMutableArray *arrayM;
代码内容:
static HLTestObject *instance = nil; + (instancetype)sharedInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ instance = [[[self class] alloc] init]; instance.height = 10; instance.object = [[NSObject alloc] init]; instance.arrayM = [[NSMutableArray alloc] init]; }); return instance; } + (instancetype)allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ instance = [super allocWithZone:zone]; }); return instance; } - (NSString *)description { NSString *result = @""; result = [result stringByAppendingFormat:@"<%@: %p>",[self class], self]; result = [result stringByAppendingFormat:@" height = %d,",self.height]; result = [result stringByAppendingFormat:@" arrayM = %p,",self.arrayM]; result = [result stringByAppendingFormat:@" object = %p,",self.object]; return result; }
4:UITextField实现左侧空出一定的边距
就是通过uitextfield的leftview来实现的,同时要设置leftviewmode。
如果设置左右边距,需要再加上rightView功能
-(void)setTextFieldLeftPadding:(UITextField *)textField forWidth:(CGFloat)leftWidth { CGRect frame = textField.frame; frame.size.width = leftWidth; UIView *leftview = [[UIView alloc] initWithFrame:frame]; textField.leftViewMode = UITextFieldViewModeAlways; textField.leftView = leftview; }
5:UICollectionView异步加载的实例
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString * CellIdentifier = @"Event"; EventCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; Event *event = [events objectAtIndex:indexPath.item]; // replace "Event" with whatever class you use for your items实体 cell.eventTitle.text = [event objectForKey:@"title"]; cell.eventImage.image = [event objectForKey:@"image"]; if (cell.eventImage.image == nil) { NSString *imageUrl = [[[events objectAtIndex:indexPath.item] objectForKey:@"photo"] objectForKey:@"url"]; dispatch_queue_t imageFetchQ = dispatch_queue_create("image fetched", NULL); dispatch_async(imageFetchQ, ^{ __weak UICollectionView *weakCollection; NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]; UIImage *image = [UIImage imageWithData:imageData]; if (image) { dispatch_async(dispatch_get_main_queue(), ^{ [event setObject:image forKey:@"image"]; // updating the model here [weakCollection reloadItemsAtIndexPaths:@[indexPath]]; }); } }); } return cell; }
6:如何拿到别人APP图片
a:打开你Mac上的iTunes,点击我的应用, 找到刚下载好的应用, 右击在finder中显示
b:按Enter(回车键), 修改微信ipa文件的后缀为.zip, 即把微信 6.3.22.ipa变成微信 6.3.22.zip, 此处会有一个提示, 问你是否确定修改扩展名, 点击使用.zip即可
c:直接双击zip进行解压, 打开解压好的文件夹, 进入Payload文件夹 此时, 就拿到了大多数的资源. 包括css, js, 图片, MP3/4, 字体,xib等等资源
d:取Assets.car中的资源 (工具下载地址: http://pan.baidu.com/s/1kUVAT7p 提取密码: qrt5)
e:我们在上面的E步骤所在的文件夹处搜索Assets.car即可 直接将Assets.car拖入其中即可, 对, 拖进去就行了,点击start, 完成后, 点击Output Dir即可( iOS APP中所有资源 = Assets.car + .api文件解压)
以上是关于iOS开发基础知识--碎片43的主要内容,如果未能解决你的问题,请参考以下文章