学习小结6

       40天过去了,从C语言,OC,到现在UI初级的课程已经学完,时间一天天的过去,而我们,也从一个只会简单算法的学生开始向程序员迈进。
      学习就像是一个时间的沙漏,老师是沙漏上端的沙,而我们,就是一开始时沙漏下端的那个空容器,随着一天天的讲解,老师把知识一点点的倒进我们这个空空的容器里,学习时间越长,装下的东西便更多。
      而作为一个接收器,只接受不消化是不行的,因为传过来的知识若不被吸收,量满则溢,那些没有去吸收的知识也会随着时间的推移被脑子过滤掉。所以,有了老师的传授,自己再努力去接受,吸收,那么学到的懂洗就会更多。
     昨天做了一个综合的题,类似相册的浏览,把代码也复制一下,相互学习。

#import "ViewController.h"

#import "PhotoScrollView.h"

@interface ViewController ()

{

    CGFloat width;

    CGFloat height;

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    width = self.view.bounds.size.width;

    height = self.view.bounds.size.height;

    //是否自定向下偏移64px

    self.automaticallyAdjustsScrollViewInsets = NO;

    //外层滑动视图

    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];

    scrollView.delegate = self;

    //内层

    for (int i = 0; i < 5; i ++) {

        PhotoScrollView *psView = [[PhotoScrollView alloc]initWithFrame:CGRectMake(width * i, 0, width, height)];

        psView.tag = 100 + i;

        psView.img = [UIImage imageNamed:[NSString stringWithFormat:@"%d.JPG",i]];

        [scrollView addSubview:psView];

    }

    

    //内容尺寸

    scrollView.contentSize = CGSizeMake(width * 5, height);

    //分页显示

    scrollView.pagingEnabled = YES;

    //隐藏滑动条

    scrollView.showsHorizontalScrollIndicator = NO;

    scrollView.showsVerticalScrollIndicator = NO;

    [self.view addSubview:scrollView];

}




- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    

    NSInteger nowIndex = scrollView.contentOffset.x / width;

//    NSLog(@"%ld",nowIndex);

    if (nowIndex != _lastIndex) {

        PhotoScrollView *imgview =(PhotoScrollView *) [scrollView viewWithTag:_lastIndex + 100];

        imgview.zoomScale = 1;

    }

    _lastIndex = nowIndex;

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

#import "PhotoScrollView.h"

#import "UIView+viewController.h"

@implementation PhotoScrollView


- (instancetype)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        _imgView = [[UIImageView alloc]initWithFrame:self.bounds];

//         _imgView.image = self.img;

        self.delegate = self;

        [self addSubview:_imgView];

        

        //缩放倍数

        self.maximumZoomScale = 3;

        self.minimumZoomScale = 1;

        //添加单击事件

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget: self action:@selector(singelTapClick:)];

        [self addGestureRecognizer:singleTap];

        

         //添加2击事件

        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget: self action:@selector(doubleTapClick:)];

        doubleTap.numberOfTapsRequired = 2;

        [self addGestureRecognizer:doubleTap];

        [singleTap requireGestureRecognizerToFail:doubleTap];

    }

    return self;

}


//添加2击事件

- (void)doubleTapClick:(UITapGestureRecognizer *)tap

{

    if (self.zoomScale > 1) {

//        self.zoomScale = 1;

        [self setZoomScale:1 animated:1];

    }else

    {

        [self setZoomScale:3 animated:1];

    }

}


//添加单击事件

- (void)singelTapClick:(UITapGestureRecognizer *)tap

{

    BOOL show = !self.viewController.navigationController.navigationBarHidden;

    //导航栏隐藏与显示

    [self.viewController.navigationController setNavigationBarHidden:show animated:1];

    

//    [[UIApplication sharedApplication]setStatusBarOrientation:show animated:1];

    [[UIApplication sharedApplication] setStatusBarHidden:show withAnimation:UIStatusBarAnimationFade];

}


- (void)setImg:(UIImage *)img

{

    if (_img != img) {

        _img = img;

        _imgView.image = self.img;

    }

}


//缩放时

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

    return _imgView;

}



@end

#import "UIView+viewController.h"


@implementation UIView (viewController)


- (UIViewController *)viewController

{

    UIResponder *next = self.nextResponder;

    

    do {

        if ([next isKindOfClass:[UIViewController class]]) {

            return (UIViewController *)next;

        }

        next = next.nextResponder;

    } while (next);

    

    return nil;

    

}

@end


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值