Set image size to scrollview's content size after a double tap

i want to set imagesize same with the content size of the scrollview after double tap to the imageview.

i use ktphotobrowser in my app and in its ktphotoview object(it is a uiscrollview object) i have the below code for double tap

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
UITouch *touch = [touches anyObject];

if ([touch view] == self) {
  if ([touch tapCount] == 2) {
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toggleChromeDisplay) object:nil];
     //[self zoomToRect:[self zoomRectForScale:[self maximumZoomScale] withCenter:[touch locationInView:self]] animated:YES];

      //[self setContentSize:imageView_.bounds.size];
      //[self zoomToLocation:[touch locationInView:self]];

       CGPoint pointInView = [touch locationInView:self];

       // Get a zoom scale that's zoomed in slightly, capped at the maximum zoom scale specified by the scroll view
       CGFloat newZoomScale = self.zoomScale * 2.0;
       NSLog(@"zoomscale %f",newZoomScale);
       newZoomScale = MIN(newZoomScale, self.maximumZoomScale);

       // Figure out the rect we want to zoom to, then zoom to it
       CGSize scrollViewSize = self.bounds.size;

       CGFloat w = scrollViewSize.width / newZoomScale;
       CGFloat h = scrollViewSize.height / newZoomScale;
       CGFloat x = pointInView.x - (w / 2.0f);
       CGFloat y = pointInView.y - (h / 2.0f);

      CGRect rectToZoomTo = CGRectMake(x, y, w, h);

       [self zoomToRect:rectToZoomTo animated:YES];


  }
}
}

scrollview's maximumzoomscale is set to 2.0

my image's original size is 1280x853 when i double tapped myimageview's bound die height will be 640 and the height of the content size of scrollview is will be 960 (uiscreen.size.height * maximumzoomscale)

but what i want is both image view 's height and height of the content size should be same so user can not scroll to outside of image

how and where can i make these calculations and setting in this view where can i set height and widths both of them?

thanks

Answers


maybe not the best solution but i solve my problem with the below code block:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
UITouch *touch = [touches anyObject];

if ([touch view] == self) {
  if ([touch tapCount] == 2) {


     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toggleChromeDisplay) object:nil];
      [self zoomToRect:[self zoomRectForScale:[self maximumZoomScale] withCenter:[touch locationInView:self]] animated:YES];
      float abc=(self.contentSize.height-(imageView_.image.size.height*320/imageView_.image.size.width*self.maximumZoomScale))/2 *-1;

      [self setContentInset:UIEdgeInsetsMake(abc, 0, abc, 0)];





  }
 }
}

Need Your Help

How to embed snippet of HTML into a Wordpress page *without* plugins?

html wordpress embed

Searching this topic comes up with custom plugin solutions but I'd prefer to learn what's involved in doing this 'manually'. The problem:

user-scalable=no not working, is it still supported?

ios iphone zoom zooming

I'm working on a website. I need to prevent the zoom-in animation when the user selects a form, however i'm trying with this code