The company is iPad software, iPad software because the screen is wide, so the general Store for carousel figure and App iPad (pictured below) on a consistent style!
GitHub on carousel is generally applicable to iPhone style, as follows:
The iPad style is not applicable, so I’ll do it myself
Share the ideas:
says the infinite carousel figure, we first thought is: using UICollectionView to display all the pictures, and then set the pagingEnabled property to YES, plus a timer, you can achieve the effect of carousel! To achieve circular carousel, the idea is as follows:
figure: we must realize the infinite loop carousel 5 pictures, respectively in Figure 1, figure 2, figure 3, figure 4, figure 5! We need two redundant pictures, and a figure 5 is placed before figure 1. After Figure 5, place a figure 1.
- Before we display, we silently slide to second pictures, that is, figure 1 we want;
- When we slide to the right side of Figure 5 of the red frame, after the end of the slide, we silently slide to figure 5 on the right so that we can slide right and left.
- When we slide left to the last red box, figure 1, after the slide, we silently slide to the left figure 1, so that we can slide left and right.
- The final effect is to give users an infinite loop carousel effect
This effect is fine with full screen graphics, but it doesn’t work if you want to implement the effect on the iPad!
Reason: in the above method, though, we can change the position after we end the slide by the following method!
- - (void) scrollViewWillEndDragging: (UIScrollView *), scrollView, withVelocity: (CGPoint), velocity, targetContentOffset: (inout, CGPoint *) targetContentOffset;
But when we set the pagingEnabled property to YES, the above methods will not work, because we must set up a page and a page is displayed, but we want to effect is a middle page shows a complete graph, next to the 2.5 figure, this effect is not up to!
Again, since the use of existing controls as their own work, realize the effect,
Ideas are as follows:
- Let’s first customize a Cell view with a UIImageView and a UILabel on top of the Cell!
- Then create 5 Cell views, as follows
- Initialize the contents of the figure above
- Add left and right glide gestures for their parent view
- Left click gesture events: first, the frame of Figure 1 is set to frame of Figure 5, then figure 2, figure 3, figure 4, and figure 5 to move left to move the distance from the red line above. We have achieved the effect of sliding left!
- Right hand gesture events: first, the frame of Figure 5 is set to frame of Figure 1, then figure 1, figure 2, figure 3, and Figure 4 to do an animation of the distance from the red line to the right. We have achieved the right glide effect!
- If there are more than 5 pictures to be displayed, we can unify the treatment: sliding left picture array backward moving one, beyond to the first, that we can use (currentIndex + 1)% 5 to find the array index, obtaining display picture slide pictures to move an array, to less than 0 last, we can use the (currentIndex + 5-1)% 5 to find the array index, obtain the display picture
- The above mechanism we achieved regardless of how many picture carousel we simply create a 5 view by frame transform, mobile animation, we realized the infinite loop real carousel
Full code, click here