如何在放大滚动视图Objective-C时聚焦特定视图
Posted
技术标签:
【中文标题】如何在放大滚动视图Objective-C时聚焦特定视图【英文标题】:How to focus specific view while zooming in scrollview Objective-C 【发布时间】:2016-10-30 12:15:47 【问题描述】:我在 ios 应用程序中工作,其中我在滚动视图中有多个内部视图,并且我在滚动视图中启用了分页,用户还可以缩放滚动视图可以近距离查看内部视图。一切正常,但发生的事情是导航功能一一突出显示每个内部视图,但在缩放时我无法专注于每个视图。内部视图可以是文本字段、按钮和简单视图,并且可以添加到滚动视图中,例如 [scrollview addSubview:myImageView];
。
下面是我导航缩放滚动视图焦点的代码,但这不能正常工作:
- (void)showVisibleRectInZoom:(UIView*)objectToNavigate
CGFloat zoomedScaleValue =myScroll.zoomScale;
CGPoint pointToMove = CGPointMake(0.0, 0.0);
if (zoomedScaleValue > 1.0)
[myScroll scrollRectToVisible:objectToNavigate.frame animated:YES];
寻求帮助如何为每个内部视图设置滚动视图可见位置。谢谢。
【问题讨论】:
【参考方案1】:试试这些:
我认为这段代码会对你有所帮助:
- (id)initWithImage:(UIImage *)image
self = [super initWithImage:image];
if (self)
[self setUserInteractionEnabled:YES];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[doubleTap setNumberOfTapsRequired:2];
[twoFingerTap setNumberOfTouchesRequired:2];
[self addGestureRecognizer:singleTap];
[self addGestureRecognizer:doubleTap];
[self addGestureRecognizer:twoFingerTap];
[singleTap release];
[doubleTap release];
[twoFingerTap release];
return self;
#pragma mark Private
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
if ([delegate respondsToSelector:@selector(tapDetectingImageView:gotSingleTapAtPoint:)])
[delegate tapDetectingImageView:self gotSingleTapAtPoint:[gestureRecognizer locationInView:self]];
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer
if ([delegate respondsToSelector:@selector(tapDetectingImageView:gotDoubleTapAtPoint:)])
[delegate tapDetectingImageView:self gotDoubleTapAtPoint:[gestureRecognizer locationInView:self]];
- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer
if ([delegate respondsToSelector:@selector(tapDetectingImageView:gotTwoFingerTapAtPoint:)])
[delegate tapDetectingImageView:self gotTwoFingerTapAtPoint:[gestureRecognizer locationInView:self]];
查看更多:How to zoom into a selected area of image in iPhone?
-
问题是我没有定义缩放代理 - 请参阅 viewForZoomingInScrollView(页面底部):
https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/viewForZoomingInScrollView
当我切换到 Xamarin 框架时,我在 Objective C 中没有代码片段。但是 C# 解决方案如下:
scrollView.ViewForZoomingInScrollView = delegate (UIScrollView sv) return imageView; ;
其中 imageView 是包含要滚动的图像的 UIImageView。
发件人:Programatically zooming into small area of larger picture using UIScrollView
【讨论】:
以上是关于如何在放大滚动视图Objective-C时聚焦特定视图的主要内容,如果未能解决你的问题,请参考以下文章