在滚动视图中查看子视图并在“滚动顶部,左侧,右侧?”中获取问题?
添加Pinch&的代码放大子视图
UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc]
initWithTarget:self
action:@selector(twoFingerPinch:)]
autorelease];
[_childView addGestureRecognizer:twoFingerPinch];
Pinch& amp;的方法缩放儿童视图
- (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);
}
Scroll-View ContentSize设置中是否存在任何问题?
这是我的代码
谢谢
答案 0 :(得分:0)
您正在将scrollView的宽度传递给contentsize。你应该传递childView的宽度。
_scrollView.contentSize = CGSizeMake(的 _chilView 强> .frame.size.width,_childView.frame.size.height);
答案 1 :(得分:0)
修改强>
设置_scrollview框架尺寸和_childview框架尺寸相同:
//滚动视图的帧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];
并实现此委托
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return _childView;
}
同时检查XIB中的自动调整大小标志。它被设置为下限。
答案 2 :(得分:0)
_childView.frame.size.height
之后你不应该CGAffineTransform
。
This question解释得很清楚。
答案 3 :(得分:0)
我不能100%肯定你当前的情况。
但在iOS5之后,UIScrollView有以下内容: -
// `pinchGestureRecognizer` will return nil when zooming is disabled.
@property(nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);
从描述中可以看出,如果你设置了这些 -
@property(nonatomic) float minimumZoomScale; // default is 1.0
@property(nonatomic) float maximumZoomScale; // default is 1.0. must be > minimum zoom scale to enable zooming
您只需使用这些属性启用缩放即可。放大& amp;缩小应该自动适用于您,而无需实现您自己的UIGestureRecognizer。
答案 4 :(得分:0)
我已经使用以下代码删除了所有代码和更改我已经做了非常愚蠢的错误:)
_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
:)