用UIPagecontrol和UIScroller制作简易的相册(MRC状态下)

3 篇文章 0 订阅


#import "AppDelegate.h"

#import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    

    RootViewController *rootVC = [[RootViewControlleralloc] init];

    self.window.rootViewController = rootVC;

    [rootVCrelease];

    return YES;

}


//

//  RootViewController.h

//  UI-Homework-7

//

//  Created by lanouhn on 15-8-5.

//  Copyright (c) 2015 尹江涛-UIScrollView-UIPageController. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "RootView.h"

@interface RootViewController :UIViewController


@property (nonatomic ,retain)RootView *rootView;



@end


//

//  RootViewController.m

//  UI-Homework-7

//

//  Created by lanouhn on 15-8-5.

//  Copyright (c) 2015 尹江涛-UIScrollView-UIPageController. All rights reserved.

//


#import "RootViewController.h"


@interface RootViewController ()<UIScrollViewDelegate>


@end


@implementation RootViewController

- (void)loadView

{

    [superloadView];

    

    self.rootView = [[RootViewalloc] initWithFrame:[UIScreenmainScreen].bounds];

    

   self.view =self.rootView;

    

}

- (void)viewDidLoad {

    [superviewDidLoad];

    

    //添加点击事件

    //scrollView代理

    self.rootView.scrollView.delegate = self;

    

    

    //pageControl

    [self.rootView.pageControladdTarget:selfaction:@selector(pageControlAction:)forControlEvents:UIControlEventValueChanged];

    

    //定时器

    [NSTimertimerWithTimeInterval:2target:selfselector:@selector(walk)userInfo:nilrepeats:YES];

    

    // Do any additional setup after loading the view.

}


#pragma mark - scrollView的代理事件

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    //获取偏移量

   CGPoint offSet = scrollView.contentOffset;

    

    //当前的点数的下标

   NSInteger index = offSet.x /self.rootView.frame.size.width;

    

    self.rootView.pageControl.currentPage = index;

    

}


- (void)pageControlAction:(UIPageControl *)sender

{

    self.rootView.scrollView.contentOffset = CGPointMake(sender.currentPage *sender.frame.size.width,0);

    

}

- (void)walk

{

    

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)dealloc

{

    [_rootView release];

    [superdealloc];

}


@end


//

//  RootView.h

//  UI-Homework-7

//

//  Created by lanouhn on 15-8-5.

//  Copyright (c) 2015 尹江涛-UIScrollView-UIPageController. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface RootView :UIView


@property (nonatomic ,retain)UIPageControl *pageControl;


@property (nonatomic ,retain)UIScrollView *scrollView;



@end


//

//  RootView.m

//  UI-Homework-7

//

//  Created by lanouhn on 15-8-5.

//  Copyright (c) 2015 尹江涛-UIScrollView-UIPageController. All rights reserved.

//


#import "RootView.h"


@implementation RootView

- (instancetype)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        [selfaddSubviews];

    }

    return self;

    

}

- (void)addSubviews

{

    self.backgroundColor = [UIColorbrownColor];

    

    // scrollView

    self.scrollView = [[UIScrollViewalloc] initWithFrame:self.frame];

    

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

        // 创建image

       UIImage *image = [UIImageimageNamed:[NSStringstringWithFormat:@"Zombie%d.tiff",i+1]];

        // 创建imageView

       UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(i *self.frame.size.width,0, self.frame.size.width,self.frame.size.height)];

        //装载image

        imageView.image = image;

        

        [self.scrollViewaddSubview:imageView];

        

        [imageViewrelease];

        

    }

    

    self.scrollView.contentSize =CGSizeMake(self.frame.size.width * 22, self.frame.size.height);

    

    self.scrollView.pagingEnabled =YES;

    

    [selfaddSubview:self.scrollView];

    [self.scrollViewrelease];

    

    //pageControl

   self.pageControl = [[UIPageControlalloc] initWithFrame:CGRectMake(0,self.frame.size.height-45, self.frame.size.width,45)];

    

    self.pageControl.numberOfPages =22;

    

    self.pageControl.currentPageIndicatorTintColor = [UIColorredColor];

    self.pageControl.pageIndicatorTintColor = [UIColorblueColor];

    

    [selfaddSubview:self.pageControl];

    [self.pageControlrelease];

}


- (void)dealloc

{

    [_pageControl release];

    [_scrollView release];

    

    [superdealloc];

}


@end





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值