ios 实现引导页面效果
2014-05-01 22:00
375 查看
//
// ViewController.m
// UIScrollView-分页
//
// Created by 朱立志 on 14-5-1.
// Copyright (c) 2014年 朱立志. All rights reserved.
//
#define count 5
#import "ViewController.h"
@interface ViewController ()
{
UIPageControl *_control;
UIScrollView *scrollView;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
UIScrollView *uiScrollview = [[UIScrollView
alloc] init];
uiScrollview.frame = self.view.bounds;
CGFloat width =
self.view.frame.size.width;
CGFloat height =
self.view.frame.size.height;
[self.view
addSubview:uiScrollview];
for (int i = 0; i <
count; i++) {
NSString *imageName = [NSString
stringWithFormat:@"pages.bundle/%d.jpg" ,i+1];
UIImage *image = [UIImage
imageNamed: imageName];
UIImageView *imageView = [[UIImageView
alloc] initWithImage:image];
imageView.frame =
CGRectMake(i*width, 0, width, height);
[uiScrollview addSubview:imageView];
}
scrollView = uiScrollview;
uiScrollview.showsHorizontalScrollIndicator =
NO;
uiScrollview.contentSize =
CGSizeMake(count*width, height);
uiScrollview.pagingEnabled =
YES;
uiScrollview.backgroundColor = [UIColor
grayColor];
uiScrollview.delegate =
self;
UIPageControl *control = [[UIPageControl
alloc] init];
control.numberOfPages =
count;
control.bounds = CGRectMake(0, 0, 200, 50);
control.center = CGPointMake(width*0.5, height-50);
control.currentPage = 0;
_control = control;
[_control addTarget:self
action:@selector(onPointClick)
forControlEvents:UIControlEventValueChanged];
[self.view
addSubview:control];
}
- (void) onPointClick
{
NSLog(@"onPointClick");
CGFloat offsetX =
_control.currentPage * scrollView.frame.size.width;
[UIView animateWithDuration:0.3
animations:^{
scrollView.contentOffset =
CGPointMake(offsetX, 0);
}];
}
- (void)didReceiveMemoryWarning
{
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int pageNum = scrollView.contentOffset.x / scrollView.frame.size.width;
_control.currentPage = pageNum;
}
@end
// ViewController.m
// UIScrollView-分页
//
// Created by 朱立志 on 14-5-1.
// Copyright (c) 2014年 朱立志. All rights reserved.
//
#define count 5
#import "ViewController.h"
@interface ViewController ()
{
UIPageControl *_control;
UIScrollView *scrollView;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
UIScrollView *uiScrollview = [[UIScrollView
alloc] init];
uiScrollview.frame = self.view.bounds;
CGFloat width =
self.view.frame.size.width;
CGFloat height =
self.view.frame.size.height;
[self.view
addSubview:uiScrollview];
for (int i = 0; i <
count; i++) {
NSString *imageName = [NSString
stringWithFormat:@"pages.bundle/%d.jpg" ,i+1];
UIImage *image = [UIImage
imageNamed: imageName];
UIImageView *imageView = [[UIImageView
alloc] initWithImage:image];
imageView.frame =
CGRectMake(i*width, 0, width, height);
[uiScrollview addSubview:imageView];
}
scrollView = uiScrollview;
uiScrollview.showsHorizontalScrollIndicator =
NO;
uiScrollview.contentSize =
CGSizeMake(count*width, height);
uiScrollview.pagingEnabled =
YES;
uiScrollview.backgroundColor = [UIColor
grayColor];
uiScrollview.delegate =
self;
UIPageControl *control = [[UIPageControl
alloc] init];
control.numberOfPages =
count;
control.bounds = CGRectMake(0, 0, 200, 50);
control.center = CGPointMake(width*0.5, height-50);
control.currentPage = 0;
_control = control;
[_control addTarget:self
action:@selector(onPointClick)
forControlEvents:UIControlEventValueChanged];
[self.view
addSubview:control];
}
- (void) onPointClick
{
NSLog(@"onPointClick");
CGFloat offsetX =
_control.currentPage * scrollView.frame.size.width;
[UIView animateWithDuration:0.3
animations:^{
scrollView.contentOffset =
CGPointMake(offsetX, 0);
}];
}
- (void)didReceiveMemoryWarning
{
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int pageNum = scrollView.contentOffset.x / scrollView.frame.size.width;
_control.currentPage = pageNum;
}
@end
相关文章推荐
- ios 实现引导页面效果
- IOS控件之ScrollView,PageControl---APP首次打开引导页面效果实现~
- iOS 引导图的聚光灯效果代码实现
- iOS现成的引导页面的实现:纯代码
- IOS——实现左右滑动一半页面的效果
- Android实现自适应正方形GridView(陌陌引导页面效果)
- 网页引导:jQuery插件实现的页面功能介绍引导页效果
- 2015-12-8-一个功能引导页面的实现思路(效果参考:美丽说app)
- Android实战简易教程-第四十八枪(App引导页面效果实现)
- iOS实现动态元素的引导图效果
- Android实现自适应正方形GridView(陌陌引导页面效果)
- IOS UIScrollView + UIButton 实现segemet页面和顶部标签页水平滚动效果
- IOS——使用ScrollView和PageController实现引导页分页效果
- iOS简单引导页面的实现,只在用户第一次登录时出现,以后不出现
- iOS 中实现功能引导页面
- iOS开发 - 三方库实现聚光引导效果与触摸跟踪动效
- iOS实现时间线列表效果(例如订单详情页面的效果)
- Android实战简易教程<四十八>(App引导页面效果实现)
- iOS简单实现引导页面
- IOS9.0-Swift 引导页面实现