美文网首页iOS学习iOS学习开发iOS学习笔记
STF大学iOS教程中的demo--ShutterbugC

STF大学iOS教程中的demo--ShutterbugC

作者: 静赏月之美 | 来源:发表于2016-11-01 23:42 被阅读70次

    今天继续,这两天的程序比较小,所以能连着更新两天。

    在今天的这个ShutterbugC中,老爷子用了好多的setter和getter。向我们展示了各种情况。
    比如惰性初始化。

    - (UIImageView *)imageView
    {
        if (!_imageView)
        {
            _imageView = [[UIImageView alloc] init];
        }
        return  _imageView;
    }
    

    还有这个...

    - (UIImage *)image
    {
        return self.imageView.image;
    }
    
    - (void)setImage:(UIImage *)image
    {
        self.imageView.image = image;
        
        self.scrollView.zoomScale = 1.0;
        self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        
        self.scrollView.contentSize = self.image ? self.image.size : CGSizeZero;
    }
    
    

    除此之外,还有NSURL的使用

    NSURLRequest *request = [NSURLRequest requestWithURL:self.imageURL];
            
            NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
            
            NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
            
            NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request
                                                            completionHandler:^(NSURL *localfile, NSURLResponse *response, NSError *error){
                if (!error)
                {
                    if ([request.URL isEqual:self.imageURL])
                    {
                        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:localfile]];
                        dispatch_async(dispatch_get_main_queue(), ^{
                            self.image = image;
                        });
                    }
                }
            }];
            [task resume];
    
    

    最后要说的就是tableView。这个说过的人太多了,就不多说了。只说一点,就是关于在StoryBoard中添加refresh control。这个当时视频没好好看,最后只要问度娘。

    屏幕快照 2016-11-01 下午11.35.44.png

    只要把里面的Refreshing设置成为Enabled的,refresh control控件就会自动添加了。

    要说明下,老爷爷的程序是ipad和iPhone 都支持的,但是我把ipad部分选择性遗忘了...所以..就这样吧

    最后,程序地址:https://github.com/Labrador2008/STF_iOS7/tree/master/ShutterbugC

    相关文章

      网友评论

        本文标题:STF大学iOS教程中的demo--ShutterbugC

        本文链接:https://www.haomeiwen.com/subject/urcvuttx.html