UIPageControl用於提示此用者此頁面有多重顯示,

此元件的行為類似翻頁的動作,本範例為放置三張圖片,

滑動頁面與點擊UIPageControl替換圖片顯示,

並添加一個UIViewAnimationOptionTransitionFlipFromRight動畫效果。


#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIPageControl *myPageControl;
@property (weak, nonatomic) IBOutlet UIImageView *myImage;
- (IBAction)pageChanged:(UIPageControl*)sender;
- (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)pageChanged:(UIPageControl*)sender {
    
    _myImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"photo%ld.jpg",sender.currentPage+1]];
    
}

- (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender {
    
    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
        _myPageControl.currentPage++;
        
        [UIView transitionWithView:_myImage duration:0.5f options:UIViewAnimationOptionTransitionFlipFromRight 
animations:^{_myImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"photo%ld.jpg",_myPageControl.currentPage+1]];} completion:nil]; }else{ _myPageControl.currentPage--; [UIView transitionWithView:_myImage duration:0.5f options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{_myImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"photo%ld.jpg",_myPageControl.currentPage+1]];} completion:nil]; } } @end

 

arrow
arrow
    文章標籤
    UIPageControl
    全站熱搜

    Will 發表在 痞客邦 留言(0) 人氣()