last wrote a about scrolling using scroll implementation of the Carousel, today is nothing to do a scroll up and down the font rotation, the general idea is the same.
if you want to achieve scrolling up and down the carousel, first of all to determine a few
1.scroll Visible range (scrollable range)
2.contentSize (max scrolling range)
3. There are, of course, data sources, and about scrolling similar, item+2 good, determined that these points have a way of thinking can be directly to the code declared properties
@property (Strong, Nonatomic) Uiscrollview * verticalscroll;//The parent view that hosts the data
@property (strong, nonatomic) Nsarray * titlearrays;//Data source
@property (Strong, Nonatomic) Nstimer * mytimer;//Timer Control Carousel
data source (data processed here, number +2)
-(Nsarray *) titlearrays{
if (!_titlearrays) {
_titlearrays = [Nsarray arraywithobjects:@ "Today is a fine day", @ " Temperatures reached more than 30 degrees ", @" but I do not feel very hot ", @" because of what ", @" the company opened air-conditioning ", @" This is not can have ah ", @" Today is a good weather ", @" Temperature reached 30 degrees above ", nil];
}
return _titlearrays;
}
The parent view includes the creation of the data
-(Uiscrollview *) verticalscroll{if (!_verticalscroll) {_verticalscroll = [[Uiscrollview alloc]init];
_verticalscroll.center = Cgpointmake (SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
_verticalscroll.bounds = CGRectMake (0, 0, 130, 60);
_verticalscroll.pagingenabled = YES;
_verticalscroll.showsverticalscrollindicator = NO;
_verticalscroll.scrollenabled = NO;
_verticalscroll.bounces = NO;
_verticalscroll.delegate = self;
[Self.view Addsubview:_verticalscroll];
CGFloat Scaleh = 20;
CGFloat Height = 20;
CGFloat H = 0; for (int i =0; i<self.titlearrays.count; i++) {UIButton * button = [UIButton Buttonwithtype:uibuttontypecu
Stom];
Button.frame = CGRectMake (H+scaleh, Cgrectgetwidth (_verticalscroll.frame) -20, Height);
[Button settitle:self.titlearrays[i] forstate:uicontrolstatenormal]; [Button Settitlecolor:[uicolor Redcolor] Forstate:uicoNtrolstatenormal];
Button.tag = i+10;
[_verticalscroll Addsubview:button];
H = Button.frame.origin.y+button.frame.size.height+scaleh;
} _verticalscroll.contentsize = Cgsizemake (0, H);
return _verticalscroll; }
also a control unlimited carousel timer (I was created when entering the interface, according to the requirements of the project)
-(void) Viewwillappear: (BOOL) animated{
self.verticalScroll.backgroundColor = [Uicolor whitecolor];
_mytimer = [Nstimer scheduledtimerwithtimeinterval:1.5 target:self selector: @selector (changescrollcontentoffsety) Userinfo:nil Repeats:yes];
[[Nsrunloop Currentrunloop] Addtimer:_mytimer formode:nsrunloopcommonmodes];
}
Implement Timer Method
-(void) changescrollcontentoffsety{
//start timer
cgpoint point = Self.verticalScroll.contentOffset;
[Self.verticalscroll setcontentoffset:cgpointmake (0, Point.y+cgrectgetheight (self.verticalScroll.frame)) animated : YES];
of course, the rolling agent is also needed. Because this is not considered manual sliding can scroll, so write only one agent agreement, the code is as follows
-(void) Scrollviewdidendscrollinganimation: (Uiscrollview *) ScrollView
{
NSLog (@ "Endani");
if (Scrollview.contentoffset.y==scrollview.contentsize.height-cgrectgetheight (Self.verticalScroll.frame)) {
[ScrollView setcontentoffset:cgpointmake (0, Cgrectgetheight (self.verticalScroll.frame))];
}
The last timer remembers to destroy when exiting this interface
-(void) Viewwilldisappear: (BOOL) animated{
[_mytimer invalidate];
_mytimer = nil;
}
to this, an infinite scrolling of the upper and lower font of the carousel, is made. Of course the code words are still relatively rotten, there are insufficient places please point out that I will change in time. Last record this article is for reference only, demo address