简体   繁体   English

在UITableView中用手指在屏幕上绘制

[英]Drawing in screen with finger in UITableView

I am following this excellent small tutorial about drawing on screen in the layer of a UIView (subclass). 我正在按照这个关于在UIView(子类)层中的屏幕上绘制的优秀小教程进行操作。 http://spritebandits.wordpress.com/ It just works. http://spritebandits.wordpress.com/即可使用。

There is just one thing. 只有一件事。 I placed this view as subview of a UITableViewCell which, naturally, is displayed as part of a UITableView. 我将此视图放置为UITableViewCell的子视图,该子视图自然显示为UITableView的一部分。 I guess I would have the same issue when I would place it within an UIScrollView. 我猜我将其放在UIScrollView中时也会遇到同样的问题。 (UITableView inherits from UIScrollView anyway) (UITableView始终从UIScrollView继承)

Touches are triggered by my painting view as long as their related movement is horizontal. 只要触摸的相关动作是水平的,它们就会由我的绘画视图触发。 As soon as I move the finger kinda vertical, even partly, then the UITableView takes over and scrolls the table. 一旦我将手指稍微垂直移动,甚至部分移动,UITableView就会接管并滚动表。

Is there any proper way of stopping the Table to taike control of the touches while the touch is actually within my view? 当触摸实际上在我的视野范围内时,是否有任何适当的方式停止Table来控制触摸?

If it is of importance: I am using storyboard. 如果它很重要:我正在使用情节提要。 The cell is a prototype cell with its own subclass of UITableViewCell. 该单元是具有自己的UITableViewCell子类的原型单元。

I've implemented this using the same class "Canvas" you're saying and also inside a UITableViewCell. 我已经使用与您说的相同的类“ Canvas”以及在UITableViewCell中实现了此功能。 But I didn't use the entire cell for drawing, only a UIView inside of the UITableView as a subview. 但是我没有使用整个单元格进行绘制,只是将UITableView内部的UIView用作子视图。

I reached the whole user experience by activating and deactivating the UITableView scrolling when that UIView (subview of the cell where I allow the drawing) fires touchesBegan or touchesEnded. 当该UIView(允许绘制的单元格的子视图)触发touchesBegan或touchesEnded时,我通过激活和停用UITableView滚动达到了整个用户体验。 So when they touch/move inside the UIView, they're drawing. 因此,当他们在UIView中触摸/移动时,他们正在绘图。 When it's outside, they're scrolling. 在外面时,他们正在滚动。 So they can't scroll on the UIView because they will be drawing. 因此,它们将无法绘制,因此无法在UIView上滚动。

The problem in your case is that since the whole cell is the view for drawing, the user cannot scroll in this concrete cell because it's the drawing one. 您所遇到的问题是,由于整个单元格都是用于绘制的视图,因此用户无法在此具体单元格中滚动,因为它是绘图中的一个。

Hope this will help. 希望这会有所帮助。

I dont have an answer for that. 我没有答案。 But there is essentially a work around. 但是本质上是可以解决的。

You could get the user in to a drawing mode, where the scrolling for a UItableviewcell is disabled and then 您可以使用户进入绘图模式,在该模式下,禁用UItableviewcell的滚动,然后

once the user is done with drawing, you could enable scrolling again. 用户完成绘制后,可以再次启用滚动。

Inclusion of a button anywhere on the screen would help you switch modes. 在屏幕上的任意位置包含按钮将帮助您切换模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM