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
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。