UIView 弹出窗口,如 UIAlertView
我想要一个可以像 UIAlertView 一样弹出并且可以移动的 UIView。
有什么帮助吗?
谢谢。
I Want a UIView which can popup like UIAlertView and also can move.
Any help please??
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 UIView 动画对视图的变换进行动画处理 (使用块或旧版 API)
从一些非常小的尺寸(例如
view.transform = CGAffineTransformMakeScale(0.1, 0.1)
)到更大一点的尺寸然后你希望它是(例如view.transform = CGAffineTransformMakeScale(1.1, 1.1))
,然后回到所需的大小(view.transform = CGAffineTransformMakeScale(0.1, 0.1))
code>,或添加更多步骤以获得更大的弹跳。要移动它,请实现 触摸方法并随着手指的移动改变视图的框架。
编辑:这里是自定义 UIAlertView 类似 UIView 的示例代码。
MyAlertView.h:
MyAlertView.m:
然后在您想要显示该警报的地方,您需要:
并且:
然后使用
[alert show];
显示它,使用[alert hide]; 隐藏它
,或使用[警报切换]进行切换;
您还可以在点击并拖动时移动它(除了关闭按钮之外的任何位置)。我希望这足以让您开始。如果您需要代码任何部分的解释,请询问。
哦,请注意,我将此视图的颜色设置为白色,因此如果您将其显示在其他白色视图之上,您将不会真正看到它,所以只需更改任何视图的背景颜色:)
Animate the view's transform using UIView animation (using blocks or older api)
from some really small size (like
view.transform = CGAffineTransformMakeScale(0.1, 0.1)
) to something a little bigger then you want it to be (likeview.transform = CGAffineTransformMakeScale(1.1, 1.1))
, then back to the desired size(view.transform = CGAffineTransformMakeScale(0.1, 0.1))
, or add more steps for bigger bounce.And for moving it around, implement the touch methods and change the view's frame as the finger moves.
Edit: here is the sample code for custom UIAlertView-like UIView.
MyAlertView.h:
MyAlertView.m:
Then where you want to show that alert, you need:
and:
then you show it using
[alert show];
, hide using[alert hide];
, or toggle using[alert toggle];
You can also move it around when you tap and drag (anywhere except on the close button). I hope this is enough to get you started. If you need explanation for any part of code just ask.
Oh, and notice I set the color of this view to white so if you show it on top of other white view, you won't really see it, so just change the background color of any view :)
您只需按照以下步骤即可获得它:
3.现在您可以在ViewB上添加任何视图。
最后,您可以在需要时呈现此视图。效果是,ViewA 将覆盖背景视图控制器,ViewB 将作为背景视图控制器的抑制效果,B 上的视图是您将看到的 UIElement。
对于动画效果,您可以在 ViewB 上的 UIElement 上使用一些基本动画代码。
You can acquire that simply following the following steps
3.Now you can add any view on ViewB.
Finally you can Present this view where ever required. The effect will be, ViewA will cover the Background viewController, ViewB will server as suppressing effect for background view controller and views on B are the UIElement you will see.
For Animation effect you can use some basic animation code on the UIElement on ViewB.