触摸并下拉视图 [英] Touch and pull down a view

查看:89
本文介绍了触摸并下拉视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在界面顶部(状态栏下方)有一个uiview,只显示它的底部。



实际上,我想让红色uiview向下滑动以完全显示拖动,例如本机iOS中的通知中心,而不仅仅是通过点击按钮。 / p>

我应该用什么来触摸和拉下uiview以便它可以完全显示?



< img src =https://i.stack.imgur.com/ZotgY.pngalt =示例>

解决方案

创建 UIView 的子类。



覆盖 touchesBegan:withEvent touchesMoved:withEvent



touchesBegan 或许进行视觉上的改变,以便用户知道他们正在触摸视图。
在touchesMoved中使用
[[touches anyObject] locationInView:self]

[ [触摸任何对象] previousLocationInView:self]



计算当前触摸位置与最后触摸位置之间的差异(检测向下拖动或拖动备份)。



然后,如果您是自定义绘图,请致电 [self setNeedsDisplay] 告诉您的观点重新绘制它的 drawRect:(CGRect)rect 方法。



注意:这假定这不使用多次触摸查看。


I have a uiview at the top of the interface (below the status bar) that only the bottom part of it is shown.

Actually, I want to make the red uiview to slide down to be entirely shown by drag such as the notificationcenter in the native iOS and not just by taping a button.

What should I use to "touch and pull down" the uiview so it could be shown entirely ?

解决方案

Make a subclass of UIView.

Override touchesBegan:withEvent and touchesMoved:withEvent.

In the touchesBegan perhaps make a visual change so the user knows they are touching the view. In the touchesMoved use [[touches anyObject] locationInView:self] and [[touches anyObject] previousLocationInView:self]

to calculate the difference between the current touch position and the last touch position (detect drag down or drag back up).

Then if you're custom drawing, call [self setNeedsDisplay] to tell your view to redraw in it's drawRect:(CGRect)rect method.

Note: this assumes multiple touch is not used by this view.

这篇关于触摸并下拉视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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