模仿 iOS 横幅样式通知/应用程序导航中的功能
我目前已将应用程序设置为接收推送通知。当我在应用程序中并收到推送通知时,我有一个自定义 UIView 从屏幕顶部向下滑动并显示通知(类似于新版本的 Whatsapps)。本质上,我试图模仿 iOS 5 中的横幅样式通知。
我现在要做的是让 UIView 可点击。单击时,根据收到的通知类型,会将我带到不同的视图控制器(类似于 Whatsapp 的做法)。
例如,我在聊天室 A 中。我在聊天室 B 中收到一条消息。滑块视图下降,我点击它,它会将我带到聊天室 B。在推送通知中,我本质上是传递 chatroomID,我可以用它来识别我想加入哪个房间(基本上是一些景观)。
我已经有了一个带有导航控制器的根视图控制器设置。当用户在整个应用程序中导航时,我正在模态地推送其他视图控制器。收到通知时我会关闭当前视图并推送下一个视图吗?
另外,我将如何让我的滑块视图检测像 iOS 横幅通知这样的点击? (也许有一个选定的动画,类似于 UITableView 中的“灰色点击样式”)?
I currently have my app setup to receive push notifications. When I am in the app and I receive a push notification, I have a custom UIView slide down from the top of the screen and displays the notification (similar to the new version of Whatsapps). Essentially I am trying to mimic the banner style notifications in iOS 5.
What I am looking to do now is have that UIView clickable. When clicked, based off of the type of notification received, will bring me to a different view controller (similar to how whatsapp does it).
For example, I am in chatroom A. I receive a message in chatroom B. The slider view comes down, I tap that and it brings me to chatroom B. In the push notification I am essentially passing the chatroomID which I can use to identify which room (essentially some view) I would like to join.
I have a root view controller setup already with a navigation controller as well. I am modally pushing other view controllers as the user navigates throughout the app. Would I dismiss the current view and push the next view when receiving a notification?
Also how would I go about making my slider view detect taps like the iOS banner notification? (and maybe have a selected animation, similar to the "grey clicked style" in a UITableView)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是检测视图点击的技巧:使用
UIControl
而不是UIView
(UIControl
是UIView< 的超类) /代码>)。然后使用
UIControl
的addTarget:action:forControlEvents:
方法和UIControlEventTouchUpInside
的 controlEvents 来发送点击视图时,您的选择会显示一条消息。如果您在 Xcode 的图形编辑器中配置视图,则可以使用身份检查器的 Class 字段将视图的类从UIView
更改为UIControl
,然后您可以配置 Touch Up Inside 事件。(我从 Conway 和 Hillegass 的《iOS 编程:大书呆子牧场指南》中学到了这项技术。)
Here's a trick for detecting a tap on a view: Use a
UIControl
instead of aUIView
(UIControl
is a superclass ofUIView
). Then use theUIControl
'saddTarget:action:forControlEvents:
method with controlEvents ofUIControlEventTouchUpInside
to send the object of your choice a message when the view is tapped. If you're configuring the view in Xcode's graphical editor, you can use the Identity inspector's Class field to change the class of your view fromUIView
toUIControl
, and then you can configure the Touch Up Inside event.(I learned this technique from iOS Programming: The Big Nerd Ranch Guide by Conway and Hillegass.)
您可以非常轻松地在视图上显示一个清晰的按钮,并使用符合您的条件的“if”语句,并从那里执行视图动画并转换回另一个视图。
You could very easily present a clear button over the view with an "if" statement that matches your criteria and perform a view animation from there with the transition back to the other view.