Sagit.Framework For IOS auto layout tutorial: 14. Uiscrollview: paging, pagination component rendering, paging event, setting page size, batch loading image rendering.



This article introduces some usages of uiscrollview encapsulation.

1. Special usage of uiscrollview: paging, paging events, batch loading images.

Basic definition:

interface UIScrollView (ST)
//Define two events, the previous page and the next page
typedef void (^OnScrollPrePager)(UIScrollView *scrollView);
//Define two events, the previous page and the next page
typedef void (^OnScrollNextPager)(UIScrollView *scrollView);
//! previous event
@property (nonatomic,copy)OnScrollPrePager onPrePager;
//! next page event
@property (nonatomic,copy)OnScrollNextPager onNextPager;
//! index of current page
@property (nonatomic,assign)NSInteger pagerIndex;
//! coordinates to start sliding
@property (nonatomic,assign)CGPoint startPoint;
//! coordinates when the hand is released
@property (nonatomic,assign)CGPoint endPoint;
//! sliding direction
@property (nonatomic,assign)XYFlag direction;
//! is the picture full screen
@property (nonatomic,assign)BOOL isImageFull;

//! binding events add events to all child views in the form of code blocks
-(UIScrollView*)removeAt:(NSInteger) index;
-(UIScrollView *)removeAt:(NSInteger)index moveXY:(BOOL)yesNO;
#Pagma mark pagination component
@property (readonly,nonatomic,retain)UIPageControl *pager;

#pragma mark Add Images
-(UIScrollView *)addImages:(id)imgOrName,...NS_REQUIRES_NIL_TERMINATION;

2. Some example code 1:

[[[self.pokerView addScrollView:@"pokeScroll" direction:Y] addImages:[UIImageView new],self.magicImg, nil] block:nil on:^(UIScrollView* poker)
        [poker backgroundColor:ColorBlack];
        poker.onPrePager = ^(UIScrollView *scrollView) {
            //Remove previous and previous pages
            [scrollView removeAt:scrollView.pagerIndex+1];
            [self setProximityM onitoring:YES ]; // turn on distance sensing (so that the hand can dance to cancel the display of cards)

3. Some example code 2:

[[[sagit addScrollView:nil direction:X] addImages:self.rndImgName,nil ] block:nil on:^(UIScrollView* scroll)
        //7 photos (ensure fast time reversal)
        for (NSInteger i=0; i<=5; i++) {
            [scroll addImageView:nil img:self.rndImgName direction:X];
        [scroll onClick:^(UIScrollView* me)
            [ Sagit.MsgBox  Confirm: @ "confirm card selection?" title: @ "message prompt" click: ^ bool (nsinteger btnindex, UIAlertView * view){
                    NSString *imgName=me.subviews[me.pagerIndex].asImageView.imageName;
                    self.readyImg=[[UIImageView alloc] initWithImage:me.subviews[me.pagerIndex].asImageView.image];
                        [Sagit.Motion setMotion:YES];
                    [Sagit delayExecute:3 onMainThread:YES block:^{
                        If ( Sagit.Magic.Setting . istakeuserphoto) // enable video capture
                            [Sagit.Video start];
                            [Sagit delayExecute:1 onMainThread:YES block:^{
                                [Sagit.Video takePhoto:^(NSData *data) {
                                    [email protected][data];
                                    [Sagit.Video stop];
                        else if(Sagit.Magic.Setting.isUseAnimal)
                            NSString *animalName=[self getAnimalName:imgName seek:seekRnd];
                            [email protected][STImage(animalName).data];
                        [self setProximityMonitoring:YES];
                return YES;
        scroll.onNextPager = ^(UIScrollView *scrollView)
            [self.lock lock];
            //[UIView animateWithDuration:0 animations:^{
            while (scrollView.pagerIndex>2) {
                [scrollView removeAt:0 moveXY:YES];
                //Remove the first and add a new one
                [scrollView addImageView:nil img:self.rndImgName direction:X];
            // [NSThread sleepForTimeInterval:0.1];
            [self.lock unlock];
           // [scrollView.pager stopTimer];
//       [scroll showPager:YES];
//       [scroll.pager startTimer:3 onTimer:nil];

4. The pagerpx attribute is added to allow you to specify the width, height and length of each page:

//! the length, or height of the page, in PX units.
@property (nonatomic,assign) NSInteger pagerPx;

By default, the length of each page is the width or height of the calculated Scrollview. For scenarios where the page size needs to be customized, this property can be set.