scrollView动画

scrollView动画



#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"minion"]];
    [self.scrollView addSubview:imageView];
    
    self.scrollView.contentSize=imageView.image.size;
}

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

- (IBAction)left:(id)sender {
    [UIView animateWithDuration:3.9 animations:^{
        self.scrollView.contentOffset = CGPointMake(0, self.scrollView.contentOffset.y);
        
    } completion:^(BOOL finished)
     {
         NSLog(@"complete");
     }];
    
}

- (IBAction)top:(id)sender {
    
    CGPoint offset=CGPointMake(self.scrollView.contentOffset.y, 0);
    [self.scrollView setContentOffset:offset animated:YES];
    
}
- (IBAction)bottom:(id)sender {
    //block设置动画
    [UIView animateWithDuration:3.0 animations:^{
        [UIView setAnimationDuration:4.0];
        CGFloat  offSetY=self.scrollView.contentSize.height-self.scrollView.frame.size.height;
       CGPoint offset = self.scrollView.contentOffset;
        offset.y=offSetY;
        self.scrollView.contentOffset=offset;
    } ];
    
    
    
}
- (IBAction)right:(id)sender {
    //代理设置动画
    [UIView beginAnimations:nil context:nil];
       [UIView setAnimationDuration:4.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(stop)];
    [UIView setAnimationWillStartSelector:@selector(start)];
    CGFloat offsetX = self.scrollView.contentSize.width - self.scrollView.frame.size.width;
    self.scrollView.contentOffset = CGPointMake(offsetX, self.scrollView.contentOffset.y);
    [UIView commitAnimations];
}
-(void)start
{
    NSLog(@"start");
}
-(void)stop
{
    NSLog(@"stop");
}
@end


你可能感兴趣的:(scrollView动画)