藍懿 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



發佈了113 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章