用UIPagecontrol和UIScroller制作简易的相册(MRC状态下)
2015-08-05 21:19
423 查看
#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
#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
相关文章推荐
- UE4蓝图术语表
- Quartz2D - 04.利用贝瑟尔路径(UIBezierPath)绘制基本图形
- Windows/MFC_三个退出程序消息:WM_CLOSE、WM_DESTROY、WM_QUIT
- UE4蓝图用户指南
- UE4蓝图简介
- Rescue
- iOS之UIView的层次结构变更
- UIPickerView的简单应用——省份/城市选择的实现
- CSS3 Media Query:移动 Web 的完美开端
- 黑马程序员——break和continue语句+函数+函数重载-第4天
- 黑马程序员—JAVA基础—GUI(图形化界面编程)
- iOS之UIView的圆角
- UIView详解
- iOS之UIView的变更动画
- 28.UIScrollView和UIPageController
- HDU 1242 Rescue
- UIScrollView
- iOS之UIImage的三中读取方法
- 【JAVA语言基础】map以value进行排序
- getRequestDispatcher()与sendRedirect()的区别