UIPageControl +循环(无限)滚动 [英] UIPageControl + circular (Infinite) scrolling
本文介绍了UIPageControl +循环(无限)滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发必须制作欢迎屏幕的应用程序.在那个 UIPageControl
中,我需要显示不同的9个子视图.在那还需要无限循环滚动.这意味着在我滑过第9页之后,应该出现比第1页滑行的情况.
我为实现它做了很多尝试,但从未获得预期的结果.
任何人都可以帮助我以获得最佳解决方案.
谢谢.
解决方案
我建议使用
I am working on app in which i have to make welcome screen. In that UIPageControl
i need to display different 9 subviews. Also need infinite circular scrolling in that. It means after page-9 if i slide than page-1 should appear.
I have tried so much to implement it but never got expected results.
Can anyone help me out to get the best solution for it.
Thanks.
解决方案
I recommended to use iCarousel for doing this task. I do following changes in to there demo Buttons Demo
.h class
@property (nonatomic, assign) BOOL wrap;
.m class
- (void)viewDidLoad
{
[super viewDidLoad];
_wrap = YES;
//configure carousel
carousel.type = iCarouselTypeLinear;
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return 9;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 400)];
view.backgroundColor=[UIColor redColor];
((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
view.contentMode = UIViewContentModeCenter;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
}
else
{
//get a reference to the label in the recycled view
label = (UILabel *)[view viewWithTag:1];
}
label.text = [NSString stringWithFormat:@"%i", index];
return view;
}
- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
//don't do anything specific to the index within
//this `if (view == nil) {...}` statement because the view will be
//recycled and used with other index values later
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 400.0f)];
view.backgroundColor=[UIColor redColor];
((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
view.contentMode = UIViewContentModeCenter;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50.0f];
label.tag = 1;
[view addSubview:label];
}
else
{
//get a reference to the label in the recycled view
label = (UILabel *)[view viewWithTag:1];
}
label.text = (index == 0)? @"[": @"]";
return view;
}
- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
switch (option)
{
case iCarouselOptionWrap:
{
//normally you would hard-code this to YES or NO
return _wrap;
}
case iCarouselOptionSpacing:
{
//add a bit of spacing between the item views
return value * 1.05f;
}
case iCarouselOptionFadeMax:
{
if (carousel.type == iCarouselTypeCustom)
{
//set opacity based on distance from camera
return 0.0f;
}
return value;
}
default:
{
return value;
}
}
}
- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform
{
//implement 'flip3D' style carousel
transform = CATransform3DRotate(transform, M_PI / 8.0f, 0.0f, 1.0f, 0.0f);
return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * carousel.itemWidth);
}
or getting tapped Button index:-
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
NSLog(@"Tapped view number: %d", index);
}
it's Output is :-
这篇关于UIPageControl +循环(无限)滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文