我已经成功地将 Three20 框架集成到我的项目中,
我扩展了 TTPhotoViewController 以添加更多内容
功能。
现在我需要向 TTPhotoView 添加一些子视图
TTPhotoViewController。我特别想添加子视图
每个 TTPhotoView 加载后。这些子视图代表
图像上的敏感区域,因此它们应该按比例缩放
图像。
用户可以点击子视图来获取有关图像的额外信息。
我不知道如何实现这种行为。我应该延长
TTPhotoView 并确保 TTPhotoViewController 使用此
扩展版本而不是 TTPhotoView?
有人能指出我正确的方向吗?
谢谢
I have successfully integrated the three20 framework in my project,
and I have extended the TTPhotoViewController to add some further
functionality.
Now I need to add some subviews to the TTPhotoView loaded by the
TTPhotoViewController. In particular I would like to add that subviews
after every TTPhotoView as been loaded. These subviews represents
sensible area over the image so they should scale proportionally with
the image.
The user can tap a subview to get extra info about the image.
I don't know how to implement this behavior. Should I extend the
TTPhotoView and make sure that the TTPhotoViewController use this
extended version instead of its TTPhotoView?
Could someone point me to the right direction?
Thank you
发布评论
评论(3)
解决了对 TTPhotoView (TapDetectingPhotoView) 进行子类化,然后将所有子视图添加到该子类的问题。
主要问题是照片切换,因为 TTPhotoViewController(特别是其内部 TTScrollView)在切换操作期间重用了 TTPhotoView。
因此,例如,如果您将子视图添加到 TTPhotoView 子类并尝试切换到下一张照片,您的子视图可能会在这里,因为 TTPhotoView 被重用。
为了解决这个问题,我决定在每次发生照片切换时添加和删除所有子视图(请参阅 TTPhotoViewController::didMoveToPhoto)。
通过这种方式,我确信每个照片视图都有其子视图。
这是我的实现(只有非凡的方法)
希望这些有帮助!
PhotoViewController.h:
PhotoViewController.m:
TapDetectingPhotoView.h:
TapDetectingPhotoView.m:
SensibleAreaView.h :
SensibleAreaView.m:
Solved subclassing the TTPhotoView (TapDetectingPhotoView) and then adding all my subviews to that subclass.
The main problem was represented by the photo switching, because the TTPhotoViewController (in particular its inner TTScrollView) reuse the TTPhotoView during switching operation.
So for example if you add your subview to your TTPhotoView subclass and try to switch to the next photo, your subview will probably be here, because the TTPhotoView is reused.
To solve this problem I decided to add and remove all my subviews every time a photo switch occur (see TTPhotoViewController::didMoveToPhoto).
In this way I'm sure that every photoview has its subviews.
Here my implementation (only remarkable methods)
Hope these help!
PhotoViewController.h:
PhotoViewController.m:
TapDetectingPhotoView.h:
TapDetectingPhotoView.m:
SensibleAreaView.h:
SensibleAreaView.m:
一些想法:
子类
TTPhotoView
,然后在TTPhotoViewController
中重写createPhotoView
:尝试重写私有方法(是的,不好的做法,但是嘿)
TTPhotoView
子类中的 >setImage::一般来说,查看
TTPhotoViewController
的标头和实现(对于私有方法)和TTPhotoView
。设置一些断点来弄清楚什么是做什么的:)Some ideas:
Subclass
TTPhotoView
, then overridecreatePhotoView
in yourTTPhotoViewController
:Try overriding a private method (yes, bad practice, but hey)
setImage:
inTTPhotoView
subclass:In general, look at the headers and implementations (for the private methods) of
TTPhotoViewController
andTTPhotoView
. Set some breakpoints to figure out what does what :)有趣的问题。 Facebook 的标签也有类似的功能。他们的标签不与图像成比例缩放。事实上,如果您缩放,它们甚至不会显示标签。我不知道这是否会对您有帮助,但我会看看(如果) Three20 如何处理标签,然后尝试扩展它。
Interesting question. Facebook has a similar functionality with their tags. Their tags do not scale proportionally with the image. In fact, they do not even show the tags if you have zoomed. I don't know if this will help you, but I would look at how (if) three20 handles tags and then maybe try to extend that.