iOS干货程序员iOS学习开发

iOS大杂烩

2017-07-17  本文已影响32人  孟轲666
  1. 看扩展名是不是.gif image 有个属性:pathExtension 就可以判断
  self.gifView.hidden = ![model.image1.pathExtension.lowercaseString isEqualToString:@"gif"];
  1. 圆形进度条的使用

使用了第三方框架DACircularProgress ,具体用法如下:

[self.pictureView sd_setImageWithPreviousCachedImageWithURL:[NSURL URLWithString:_model.image0] andPlaceholderImage:nil options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        self.progreessView.hidden = NO;
        self.progreessView.progressLabel.text = [NSString stringWithFormat:@"%d%%",(int)(1.0  * receivedSize/expectedSize * 100)];
        [self.progreessView setProgress:1.0  * receivedSize/expectedSize animated:YES];
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        self.progreessView.hidden = YES;
    }];

-> 个人觉得这个框架还是挺好的,虽然里面有点小的bug,但是使用起来很方便,至于bug自己调调就好。

3.如果要在一个非控制器(例如UIView) 中,present出一个控制器,可以使用窗口的根控制器去present。

[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:showPicture animated:YES completion:nil];

4.为了减轻第三方框架的风险,最好的做法就是自定义,然后继承自该第三方框架。
5.图片是没办法直接添加点击事件的,需要用到手势去添加,首先打开用户交互,然后添加点击事件:

//打开图片的用户交互
    self.pictureView.userInteractionEnabled = YES;
    //添加图片的点击事件
    [self.pictureView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPicture)]];
    [super awakeFromNib];

5.保存图片

- (IBAction)save {
    UIImageWriteToSavedPhotosAlbum(self.imgView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    
}

6.单例模式: 重写系统的方法-alloc方法,具体操作如下:

//0.提供全局变量
static MKTool * _instance;
  + (instancetype)allocWithZone:(struct _NSZone *)zone{
//加互斥锁解决多线程访问安全
//    if (_instance) {
//        _instance = [super allocWithZone:zone];
//    }
//本身就是线程安全的
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}

具体可以参考这篇简书:ios单例模式

7.pop和Core Animation 的区别:

8.block用copy;block是属性或者参数的写法不一样:

-(void)cancelWithCompletionBlock:(void(^)())myBlock;

9.窗口级别:(窗口是不用addsubview的方式添加到父控件上的,只需要控制窗口是否隐藏就好了,----------------window_.hidden = NO;)

const UIWindowLevel UIWindowLevelNormal;>
const UIWindowLevel UIWindowLevelStatusBar;>
const UIWindowLevel UIWindowLevelAlert;

10.菊花的显示:

    UIActivityIndicatorView * load = [[UIActivityIndicatorView alloc]init];
    load.center = CGPointMake(120, 10);
    load.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    [load startAnimating];

11.UIDynamic :可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象。重力、弹性碰撞等现象。

实例如下:

@property (nonatomic,strong) UIDynamicAnimator * animator;

- (UIDynamicAnimator *)animator{
    if (!_animator) {
        _animator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
    }
    return _animator;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //1.创建物理仿真器(ReferenceView,参照视图,其实就是设置仿真范围)
   
    //2.创建物理仿真行为 - 重力行为
    UIGravityBehavior * gravity = [[UIGravityBehavior alloc]init];
    gravity.gravityDirection = CGVectorMake(1, 1);
    gravity.magnitude = 10;
    [gravity addItem:self.blueView];
    //3.添加物理仿真行为 到 物理仿真器中
    [self.animator addBehavior:gravity];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    // 获得触摸点
    UITouch * touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    
   //创建吸附行为
    UISnapBehavior * snap = [[UISnapBehavior alloc]initWithItem:self.blueView snapToPoint:point];
    //防抖系数
    snap.damping = 1.0;
    //添加行为
    [self.animator removeAllBehaviors];
    [self.animator addBehavior:snap];
}

上一篇 下一篇

猜你喜欢

热点阅读