Created
August 7, 2016 10:13
-
-
Save jackyshan/d2ae59a7e5075611b29d1b4b824a1905 to your computer and use it in GitHub Desktop.
scrollview滑动图片拉伸
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
static CGFloat kImageOriginHight = 240.f; | |
@interface ViewController () | |
@property (strong, nonatomic) IBOutlet UIImageView *expandZoomImageView; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
self.tableView.contentInset = UIEdgeInsetsMake(kImageOriginHight, 0, 0, 0); | |
[self.tableView addSubview:self.expandZoomImageView]; | |
} | |
- (void)viewWillAppear:(BOOL)animated{ | |
[super viewWillAppear:animated]; | |
self.expandZoomImageView.frame = CGRectMake(0, -kImageOriginHight, self.tableView.frame.size.width, kImageOriginHight); | |
} | |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ | |
CGFloat yOffset = scrollView.contentOffset.y; | |
if (yOffset < -kImageOriginHight) { | |
CGRect f = self.expandZoomImageView.frame; | |
f.origin.y = yOffset; | |
CGFloat factor = ((fabs(yOffset)+kImageOriginHight)*self.view.frame.size.width)/kImageOriginHight; | |
f.origin.x = -(factor/2-self.view.frame.size.width)/2; | |
f.size.width = factor/2; | |
f.size.height = (kImageOriginHight+fabs(yOffset))/2; | |
self.expandZoomImageView.frame = f; | |
} | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment