使用CATransition实现scrollView的多张页面滚动
2013-12-25 21:21
246 查看
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"1.jpg"];
_imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
_imageView.image = image;
[self.view addSubview:_imageView];
//利用for循环创建UIImage,并且添加到数组中
_imageList = [NSMutableArray arrayWithCapacity:8];
for (int i = 1; i <= 8; i++) {
NSString *imageName = [NSString stringWithFormat:@"%d.jpg",i];
UIImage *image = [UIImage imageNamed:imageName];
[_imageList addObject:image];
}
CGFloat w = 80;
//添加pageController ---->此处的page没有做处理
UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - w) / 2, 416, w, 20)];
page.numberOfPages = 8;
[self.view addSubview:page];
}
#pragma mark 轻扫手势监听方法
- (IBAction)swipe:(UISwipeGestureRecognizer *)sender
{
//转场动画
CATransition *transition = [[CATransition alloc] init];
transition.type = @"push";
if (UISwipeGestureRecognizerDirectionLeft == sender.direction) {
transition.subtype = kCATransitionFromLeft;
_imageView.tag = (_imageView.tag + 1) % 8;
}else if (UISwipeGestureRecognizerDirectionRight == sender.direction){
transition.subtype = kCATransitionFromRight;
_imageView.tag = (_imageView.tag - 1 + 8) % 8;
}
[_imageView setImage:_imageList[_imageView.tag]];
[_imageView.layer addAnimation:transition forKey:nil];
}
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"1.jpg"];
_imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
_imageView.image = image;
[self.view addSubview:_imageView];
//利用for循环创建UIImage,并且添加到数组中
_imageList = [NSMutableArray arrayWithCapacity:8];
for (int i = 1; i <= 8; i++) {
NSString *imageName = [NSString stringWithFormat:@"%d.jpg",i];
UIImage *image = [UIImage imageNamed:imageName];
[_imageList addObject:image];
}
CGFloat w = 80;
//添加pageController ---->此处的page没有做处理
UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - w) / 2, 416, w, 20)];
page.numberOfPages = 8;
[self.view addSubview:page];
}
#pragma mark 轻扫手势监听方法
- (IBAction)swipe:(UISwipeGestureRecognizer *)sender
{
//转场动画
CATransition *transition = [[CATransition alloc] init];
transition.type = @"push";
if (UISwipeGestureRecognizerDirectionLeft == sender.direction) {
transition.subtype = kCATransitionFromLeft;
_imageView.tag = (_imageView.tag + 1) % 8;
}else if (UISwipeGestureRecognizerDirectionRight == sender.direction){
transition.subtype = kCATransitionFromRight;
_imageView.tag = (_imageView.tag - 1 + 8) % 8;
}
[_imageView setImage:_imageList[_imageView.tag]];
[_imageView.layer addAnimation:transition forKey:nil];
}
相关文章推荐
- 使用CATransition实现scrollView的多张页面滚动
- Scrollview的使用(实现页面超出后可上下滚动)
- 使用CATransition实现页面的“从左向右” “从右向左”的动画
- 使用css3属性transition实现页面滚动
- iOS的ScrollView包含TableView使用AutoLayout实现滚动
- 使用jquery实现页面滚动到底部自动加载新的信息
- 使用LinearLayout实现ListView,解决ListView和ScrollView滚动冲突
- 使用jquery实现页面滚动到底部自动加载新的信息
- 使用ScrollView实现滚动
- Android组件之使用ScrollView实现屏幕滚动【防止屏幕不够用】
- 使用ScrollView实现滚动效果
- Android实用笔记——使用ScrollView实现滚动效果
- 使用jQuery或者原生js实现鼠标滚动加载页面新数据
- 使用ScrollView实现滚动效果
- 使用ScrollView实现滚动效果 出现 ScrollView can host only one direct child (ScrollView只能包裹一个直接子元素)
- 使用jQuery或者原生js实现鼠标滚动加载页面新数据
- Android入门(35)——第十二章 使用ScrollView实现滚动效果
- 关于使用Fragment结合ViewPager实现滚动页面视图
- 使用jquery实现页面滚动到底部自动加载新的信息
- Swift - 使用UIScrollView实现页面滚动切换