蓝懿 ios技术交流和心得分享12.29

屏幕适配和点九图:

一、点九图:

UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 20, 150,50)];

    

    UIImage * image = [UIImage imageNamed:@"abc.png"];

方法一:适用于任何图片:

    //给图像设置放大边界   距左右11像素   距上下14像素

    UIEdgeInsets insets = UIEdgeInsetsMake(14, 5, 14, 5);       

//    指定图片放大的模式以及边界

    image = [image resizableImageWithCapInsets:insetsresizingMode:UIImageResizingModeStretch];

 //方法二、适用于规则的图形(各个边角相同) 

 /image = [image stretchableImageWithLeftCapWidth:image.size.width*.5topCapHeight:image.size.height*.5]; /

    [btn setBackgroundImage:image forState:UIControlStateNormal];

    [self.view addSubview:btn];

二、屏幕适配:

1、在appdelegate中创建此方法,在启动时调用此方法,获取://获取当前屏幕与基准屏幕的宽之间的比值以及高之间的比值

-(void)abc{

    if ( [UIScreen mainScreen].bounds.size.height > 480) {

        self.scaleX = [UIScreen mainScreen].bounds.size.width/320;

        self.scaleY = [UIScreen mainScreen].bounds.size.height/568;

    }else{

        self.scaleX = 1;

        self.scaleY = 1;

    }

}

2、在ViewController中

//重写cgrectmake方法

CG_INLINE CGRect

CGRectAuToMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)

{

    //根据宽高比将现有的位置信息放大

    AppDelegate * app = [UIApplication sharedApplication].delegate;

    CGRect rect;

    rect.origin.x = x*app.scaleX; rect.origin.y = y*app.scaleY;

    rect.size.width = width*app.scaleX; rect.size.height = height*app.scaleY;

    return rect;

}

3、在创建空间时用重写的cgrectmake方法创建控件;如果有xib拖拽的空间需要遍历子控件;改变子控件frame,方法如下:

-(void)layoutView:(UIView *)view{

    for (UIView * v in view.subviews) {

        [v setFrame:CGRectAuToMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width, v.frame.size.height)];

    }

 

}

加载GIF图片有两种方法:

一、在webview上加载文件

//加载到 内存中

 NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img4.duitang.com/uploads/item/201211/03/20121103120709_EBnZ3.thumb.600_0.gif

"]];

//   加载到 myWebView

   [self.myWebView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

二、用imageview加载:配置工具包

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIWebView *myWebView;

@end

@implementation ViewController

- (void)viewDidLoad {

 

    [super viewDidLoad];

self.imageview_gif = [[UIImageViewalloc]initWithFrame:CGRectMake(0, 300, 320, 300)];

    [self.view addSubview:self.imageview_gif];

    [self create];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)create

{

   

    NSString *path = [[NSBundle mainBundle] pathForResource:@"可爱" ofType:@"gif"];

    NSData *data = [NSData dataWithContentsOfFile:path];

   

    NSDictionary *gifLoopCount = [NSDictionarydictionaryWithObjectsAndKeys:

                                  [NSNumber numberWithInt:0] , (NSString *)kCGImagePropertyGIFLoopCount,nil

                                  ];

   

    NSDictionary * gifProperties = [NSDictionarydictionaryWithObject:gifLoopCount forKey:(NSString*)kCGImagePropertyGIFDictionary] ;

   

    //__bridge为桥接OC语言,使用了就不需要释放,用的c语言;

    CGImageSourceRef gif = CGImageSourceCreateWithData((__bridge  CFDataRef)(data), (__bridge CFDictionaryRef)gifProperties);

    

    CFDictionaryRef gifprops =(CGImageSourceCopyPropertiesAtIndex(gif,0,NULL));

    NSLog(@"%@",gifprops);

    

   

    NSInteger count =CGImageSourceGetCount(gif);

   

    CFDictionaryRef  gifDic = CFDictionaryGetValue(gifprops,kCGImagePropertyGIFDictionary);

    NSNumber * delay = CFDictionaryGetValue(gifDic,kCGImagePropertyGIFDelayTime);

    

    NSNumber * w = CFDictionaryGetValue(gifprops,@"PixelWidth");

    NSNumber * h =CFDictionaryGetValue(gifprops,@"PixelHeight");

    

   

    

    NSTimeInterval totalDuration  = delay.doubleValue * count;

    CGFloat pixelWidth = w.intValue;

    CGFloat pixelHeight = h.intValue;

    

   

    

    NSMutableArray *images = [[NSMutableArray alloc] init];

    for(int index=0;index

    {

        CGImageRef ref = CGImageSourceCreateImageAtIndex(gif, index, nil);

        UIImage *img = [UIImage imageWithCGImage:ref];

        [images addObject:img];

        CFRelease(ref);

        

    }

    

    CFRelease(gifprops);

    CFRelease(gif);

    

   

    

    [_imageview_gif setBounds:CGRectMake(0, 0, pixelWidth, pixelHeight)];

    

    [_imageview_gif setAnimationImages:images];

    

    [_imageview_gif setAnimationDuration:totalDuration];

    

    [_imageview_gif startAnimating];

    

 

}

学习ios  重要还是要理清楚思路  在做或者看老师代码的时候 自己多想想为什么  不要自己看着就抄       另外还是要推荐一下 蓝懿IOS这个培训机构  和刘国斌老师刘国斌老师还是很有名气的,听朋友说刘老师成立了蓝懿iOS,,老师讲课方式很独特,能够尽量让每个人都能弄明白,有的比较难懂的地方,如果有的地方还是不懂得话,老师会换个其它方法再讲解,这对于我们这些学习iOS的同学是非常好的,多种方式的讲解会理解得更全面,这个必须得给个赞,嘻嘻,还有就是这里的学习环境很好,很安静,可以很安心的学习,安静的环境是学习的基础,小班讲课,每个班20几个学生,学习氛围非常好,每天都学到9点多才离开教室,练习的时间很充裕,而且如果在练习的过程中有什么困难,随时可以向老师求助,不像其它机构,通过视频教学,有的甚至学完之后都看不到讲师本人,问点问题都不方便,这就是蓝懿与其它机构的区别,相信在刘国斌老师的细心指导下,每个蓝懿学员都能找到满意的工作,加油!

                                                                  写博客第八十天;

                                                                              QQ:565803433


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值