[英]How to Display Collection View inside tableview with custom header action like app store in IOS using Swift
[英]Display view as inside app notification in TableView Controllers
每次我在前台收到应用程序的远程推送通知时,我都试图显示一个视图。 它在视图控制器中工作正常,但不适用于表视图控制器。 对于当前可见的单元格,我找不到获取 Y position 的方法。
观察:如果有人知道如何让它始终显示在导航栏上而不是在内容视图中,那就更好了。
编辑:遵循一些代码:
//Return the current VC that the user is seeing
func getTopVC()->UIViewController?{
let application = UIApplication.shared
if application.applicationState == .active {
if let topVC = UIApplication.getTopViewController() {
return topVC
}
}
return nil
}
//Animation that shows XIB sliding down from outside the VC to Y = 0
func animateXib(xibToAnimate: ApNotificationsXibView){
let animationTime = 0.3
let originalFrame = xibToAnimate.frame
let options: UIView.AnimationOptions = [.allowUserInteraction]
UIView.animate(withDuration: animationTime, delay: 0, options: options, animations: {
xibToAnimate.frame = CGRect(x: 0, y: 0, width: originalFrame.width, height: originalFrame.height)
}) { (isEntryAnimationDone) in
//SECOND ANIMATION TO SLIDE UP
UIView.animate(withDuration: animationTime, delay: 3.0, animations: {
xibToAnimate.frame = originalFrame
}) { (done) in
xibToAnimate.removeFromSuperview()
}
}
}
//Pre set some values, Add XIB on the current VC SubView and animate it
func displayNotificationXib(sendersName: String, sendersImage: UIImage, textToShow:String, connectionType: ApUserConnection.ConnectionType?, action: ApNotificationsXibView.TypeNotification, originUserId:String){
if(isShowingXIB == false){
if let vcToShowXib = self.getTopVC(){
let xib = self.prepareXibToAdd()
if let connect = ApActiveConnectionsServices.sharedInstance.getLocalConnectionWithId(with: originUserId){
xib.setValues(title: sendersName, sendersImage: sendersImage, body: textToShow, action: action, originId: originUserId, connect: connect)
}
vcToShowXib.view.addSubview(xib)
animateXib(xibToAnimate: xib)
}
}
}
//EXTENSION of UIApplication that get the current VC that the user is seeing
class func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return getTopViewController(base: nav.visibleViewController)
} else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
return getTopViewController(base: selected)
} else if let presented = base?.presentedViewController {
return getTopViewController(base: presented)
}
return base
}
如果要在导航栏上显示自定义视图,请将视图添加到导航 controller 而不是将其添加到视图 controller 或表视图 controller。
let customView = //...
self.navigationController?.view.addSubview(customView)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.