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

加载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];

    

 

}

一、导航控制器的一些属性和基本使用

1.把子控制器添加到导航控制器中的四种方法

(1)

 1.创建一个导航控制器

    UINavigationController *nav=[[UINavigationControlleralloc]init];

2.设置导航控制器为window的根视图

    self.window.rootViewController=nav;

3.添加

    YYOneViewController  *one = [[YYOneViewController  alloc] init];

    [nav pushViewController:one animated:YES];

(2)

 1.创建一个导航控制器

       UINavigationController *nav=[[UINavigationControlleralloc]init];

 2.设置导航控制器为window的根视图

 self.window.rootViewController=nav;

 3.添加

YYOneViewController  *one = [[YYOneViewController  alloc] init];

 [nav addChildViewController:one];

(3)

 1.创建一个导航控制器

       UINavigationController *nav=[[UINavigationControlleralloc]init];

 2.设置导航控制器为window的根视图

 self.window.rootViewController=nav;

3.添加

YYOneViewController  *one = [[YYOneViewController  alloc] init];

nav.viewControllers=@[one];(添加到导航控制器的栈中)

说明:nav.viewControllers;== nav.childViewControllers;注意该属性是只读的,因此不能像下面这样写。nav.childViewControllers = @[one];

(4)最常用的方法

 YYOneViewController *one=[[YYOneViewController alloc]init];

 UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:one];

 

2.当前子控制器界面导航栏的标题以及对应返回标题的设置

    self.navigationItem.title=@"第一个界面";

    self.navigationItem.backBarButtonItem=[[UIBarButtonItemalloc]initWithTitle:@"返回一"style:UIBarButtonItemStylePlain target:nilaction:nil];

3.给导航栏添加按钮

说明:可添加一个,也可以添加多个(数组)

   添加导航栏左边的按钮(添加一个相机图标的按钮),会盖掉返回

    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];

4.界面跳转

跳转到第二个界面(当前为第三个,移除当前栈顶的控制器) [self.navigationControllerpopViewControllerAnimated:YES];

   移除处理栈底控制器之外的所有控制器  [self.navigationControllerpopToRootViewControllerAnimated:YES];

  只要传入栈中的某一个控制器,就会跳转到指定控制器 [self.navigationController popToViewController:

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

                                                                  写博客第七十六天;

                                                                              QQ:565803433



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值