如何在一个UIScrollView非滚动内容 [英] How to have non scrolling content in a UIScrollView

查看:111
本文介绍了如何在一个UIScrollView非滚动内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要像这样

+ scrollview
|
|__ moving content
|
|__ non moving content

棘手的部分是我在修改现有的一块code的,我不能使用
父滚动视图设置不可移动的内容,因为它的孩子。非移动内容
必须是一个滚动视图的孩子。我想将其连接到后台视图,但
我不知道如何访问UIScrollView的背景视图。

The tricky part is that I'm modifying an existing piece of code where I can't use the scrollview parent to set the "non moving content" as it's child. The non moving content must be a scrollview child. I was thinking of attaching it to the background view but I don't know how to access the UIScrollview's background view.

推荐答案

我相信推荐的方式做到这一点是重写layoutSubviews在自定义UIScrollView的子类。这是在2010年的WWDC会议上覆盖(IIRC),你应该能够得到,如果你是一个开发者计划的成员。

I believe the "recommended" way to do this is to override layoutSubviews in a custom UIScrollView subclass. This was covered (IIRC) in a 2010 WWDC session you ought to be able to get if you are a developer program member.

假设你不能子类UIScrollView的,你可以这样做以下(在修改现有的code给你的限制)。

Assuming you can't subclass UIScrollView (given your restrictions on modifying existing code), you can do something like the following.

让staticView是非移动内容您想保留固定的:

Let "staticView" be the "non moving content" you wish to keep fixed:

UIView *staticView;

创建伊娃(可能在您的视图控制器),以保持其初始中心:

Create an ivar (probably in your view controller) to hold its initial center:

CGPoint staticViewDefaultCenter = [staticView center]; // Say, in viewDidLoad

请您的视图控制器滚动视图的委托,如果尚未,然后实现类似如下:

Make your view controller the scroll view's delegate if it isn't already, then implement something like the following:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint contentOffset = [scrollView contentOffset];
    CGPoint newCenter = CGPointMake(staticViewDefaultCenter.x + contentOffset.x,
                                    staticViewDefaultCenter.y + contentOffset.y);
    [staticView setCenter:newCenter];
 }

这将涵盖滚动视图的简单情况。处理可缩放视图变得有点棘手,将部分取决于你如何执行你的viewForZoomingInScrollView:方法,但遵循的类似方法(​​这一次是在scrollViewDidZoom:当然)。

This will cover the simple case of a scrollable view. Handling a zoomable view gets a little trickier and will depend in part on how you have implemented your viewForZoomingInScrollView: method, but follows an analogous procedure (this time in scrollViewDidZoom: of course).

我没有通过有你staticView变换的含义想 - 你可能必须做在这种情况下一些操作太

I haven't thought through the implications of having a transform on your staticView - you may have to do some manipulations in that case too.

这篇关于如何在一个UIScrollView非滚动内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆