Having a Child-View inside Scroll- View and getting issues in Scroll on Top, Left, Right ?
Code for adding Pinch & Zoom in Child Sub-View
UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc]
initWithTarget:self
action:@selector(twoFingerPinch:)]
autorelease];
[_childView addGestureRecognizer:twoFingerPinch];
Method For Pinch & Zoom a Child-View
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
//NSLog(@"Pinch scale: %f", recognizer.scale);
CGAffineTransform transform = CGAffineTransformMakeScale(recognizer.scale, recognizer.scale);
// you can implement any int/float value in context of what scale you want to zoom in or out
_childView.transform = transform;
_scrollView.contentSize =
CGSizeMake(_scrollView.frame.size.width,_childView.frame.size.height);
}
Is there any issues in Scroll-View ContentSize setting ?
Here is my Code
Thank you
You are passing scrollView's width to contentsize. You should pass childView's width.
_scrollView.contentSize = CGSizeMake( _chilView .frame.size.width,_childView.frame.size.height);
Edit:
Set _scrollview frame size and _childview frame size same:
//Frame for scrollview 56, 92, 196, 408.
_scrollView.delegate = self;
_scrollView.minimumZoomScale = 1.0;
_scrollView.maximumZoomScale = 10;
_childView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 196, 408)];
_childView.backgroundColor=[UIColor blackColor];
[_scrollView addSubview:_childView];
[_scrollView setContentSize:_childView.frame.size];
and implement this delegate
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return _childView;
}
Also check your auto resizing flag in XIB. it is set to bottom margin.
You should not get _childView.frame.size.height
after CGAffineTransform
.
This question explain it well.
I'm not 100% sure of your current scenario.
But after iOS5, UIScrollView has following :-
// `pinchGestureRecognizer` will return nil when zooming is disabled.
@property(nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);
From the description, it appears that if you set these-
@property(nonatomic) float minimumZoomScale; // default is 1.0
@property(nonatomic) float maximumZoomScale; // default is 1.0. must be > minimum zoom scale to enable zooming
You can simply enable zooming using these properties. And zoom-in & zoom-out should work for you automatically without having to implement your own UIGestureRecognizer.
I Have removed all the code and changes with below code I have done very stupid mistake :)
_scrollView.contentSize = CGSizeMake(_childView.frame.size.width, _childView.frame.size.height);
_scrollView.maximumZoomScale = 6.0;
_scrollView.minimumZoomScale = 1.0;
_scrollView.clipsToBounds = YES;
_scrollView.delegate = self;
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
// NSLog(@"View - %@\n",_childView);
return _childView;
}
Thanx @Mavericks
:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.