The methods declared by the UIScrollViewDelegate protocol allow the adopting delegate to respond to messages from the UIScrollView class and thus respond to, and in some affect, operations such as scrolling, zooming, deceleration of scrolled content, and scrolling animations.
--------------------------
@implementation ViewController{
UIImageView *myImageView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Create UIImageView to store image
myImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nature-wallpaper-hd1.jpg"]];
// Set up scroll view content size to the size of the image
self.myScrollView.contentSize = myImageView.frame.size;
// Set yourself as delegate
self.myScrollView.delegate = self;
// Set the max zoom scale
self.myScrollView.maximumZoomScale = 4.0f;
// Add the image view onto scrollview
[self.myScrollView addSubview:myImageView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UIScrollViewDelegate methods
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"The x offset of scroll is %f and y offset is %f", scrollView.contentOffset.x, scrollView.contentOffset.y);
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return myImageView;
}
No comments:
Post a Comment