Swift UISegmentedControl在上面没有任何内容时不难处理

Swift UISegmentedControl在上面没有任何内容时不难处理,swift,uitableview,uiscrollview,uikit,uisegmentedcontrol,Swift,Uitableview,Uiscrollview,Uikit,Uisegmentedcontrol,我的问题非常具体,我必须给出代码,如果代码太复杂或复杂,很抱歉,我对UIKit有点陌生,因为我一直在学习SwiftUI而不是UIKit 我有一个非常复杂的UITableView标题和一些漂亮的动画等等,我在上面放了一个UISegmentedControl。但是,一旦UITableViewCell位于UISegmentedControl后面,它就会停止工作,并且用户与UISegmentedControl的交互功能将丢失 如果没有可视上下文和代码,这是很难解释的,这里就是 如您所见,在顶部,用户可以

我的问题非常具体,我必须给出代码,如果代码太复杂或复杂,很抱歉,我对UIKit有点陌生,因为我一直在学习SwiftUI而不是UIKit

我有一个非常复杂的
UITableView
标题和一些漂亮的动画等等,我在上面放了一个
UISegmentedControl
。但是,一旦
UITableViewCell
位于
UISegmentedControl
后面,它就会停止工作,并且用户与
UISegmentedControl
的交互功能将丢失

如果没有可视上下文和代码,这是很难解释的,这里就是

如您所见,在顶部,用户可以自由地与UISegmentedControl交互,但当我开始滚动并且表格视图单元格位于
UISegmentedControl
后面时(如预期),分段控件完全停止响应用户触摸输入

再一次,请原谅我的代码太长(可能很糟糕),我还在学习

这是我编写的UITableView的代码:

class TertiaryProfileScroll:UITableViewController{
var分段控制:UISegmentedControl!
var testBlurView:UIVisualEffectView!
var headerTitle:我的观点!
var blurView:UIVisualEffectView!
var scorect:UIView!
var scoreLabel:UILabel!
var originalBlurRect:CGRect!
var originalTitleRect:CGRect!
变量originalTestRect:CGRect!
重写func viewDidLoad(){
super.viewDidLoad()
let headerView=Secondary StretchTableHeaderView(帧:CGRect(x:0,y:0,宽度:view.bounds.width,高度:488))
让image=UIImage(命名为:“背景图片”)
UIGraphicsBeginImageContextWithOptions(CGSize(宽度:350,高度:350),false,4)
image!.draw(in:CGRect(原点:CGPoint(x:0,y:0),大小:CGSize(宽:350,高:350)))
让newImage=UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsSendImageContext()
tableView.AllowSelection=false
tableView.separatorStyle=.none
headerView.imageView.image=newImage
tableView.tableHeaderView=headerView
addTitle()
blurView.contentView.isUserInteractionEnabled=true
tableView.register(UITableViewCell.self,强制重用标识符:“单元格”)
}
重写func scrollViewDidScroll(scrollView:UIScrollView){
guard tableView.tableHeaderView!=nil else{return}
让headerView=self.tableView.tableHeaderView为!Secondary StretchyTableHeaderView
让headerGeometry=self.geometry(视图:headerView,scrollView:scrollView)
让标题几何=self.geometry(视图:标题,滚动视图:滚动视图)
(tableView.tableHeaderView as!Secondary StretchyTableHeaderView).容器视图
.alpha=CGFloat(sqrt(人头角测量法.largetitlewight))
(tableView.tableHeaderView为!Secondary StretchyTableHeaderView).imageContainer.alpha=CGFloat(sqrt(headerGeometry.LarGetItleWight))
设largeTitleOpacity=(最大值(滴定度法.LARGETITLEWIGHT,0.5)-0.5)*2
让tinyTitleOpacity=1-min(滴定几何.LargetitleLight,0.5)*2
headerTitle.alpha=CGFloat(sqrt(大容量))
blurView.contentView.Subview[1].alpha=CGFloat(sqrt(tinytletelopacity))
如果让vfxSubview=blurView.subview.first(其中:{
字符串(描述:类型(of:$0))==“\u UIVisualEffectSubview”
}) {
vfxSubview.backgroundColor=UIColor.systemBackground.withAlphaComponent(0)
}
如果让vfxBackdrop=blurView.subview.first(其中:{
字符串(描述:类型(of:$0))==“\u UIVisualEffectBackdropView”
}) {
vfxBackdrop.alpha=CGFloat(1-sqrt(滴定几何法.Largetitlewight))
}
var blurFrame=blurView.frame
变量titleFrame=headerTitle.frame
blurFrame.origin.y=max(originalBlurRect.minY,originalBlurRect.minY+滴定几何.blurOffset)
titleFrame.origin.y=originalTitleRect.minY+364
blurView.frame=blurFrame
标题框=标题框
headerView.scrollViewDidScroll(scrollView:scrollView)
}
重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
1000
}
重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
let cell=tableView.dequeueReusableCell(带标识符:“cell”)
单元格?.textLabel?.text=String(indexPath.row)
单元?.layer.zPosition=-1000
view.sendSubviewToBack(单元格!)
view.bringSubviewToFront(tableView.tableHeaderView!)
返回单元!
}
覆盖函数视图将出现(uo动画:Bool){
超级。视图将显示(动画)
self.navigationController?.setNavigationBarHidden(真,动画:假)
}
func addTitle(){
让blurEffect=UIBlurEffect(样式:UITraitCollection.current.userInterfaceStyle==.dark?.dark:.light)
blurView=UIVisualEffectView(效果:blurEffect)
blurView.frame=CGRect(x:0,y:0,宽度:UIScreen.main.bounds.size.width,高度:44+38+tableView.safeAreaInsets.top)
segmentedControl=UISegmentedControl(项:secondaryProfilePages)
segmentedControl.selectedSegmentIndex=0
segmentedControl.frame=CGRect(x:0,y:0,宽度:UIScreen.main.bounds.size.width-32,高度:30)
让scoreSize=(“+\(String(9999))”作为NSString.boundingRect(带:CGSize(width:UIScreen.main.bounds.size.width,height:CGFloat.greatestfinitemagnity),
weak var segControl: UISegmentedControl?
    // your existing code
    blurView.contentView.addSubview(headerTitle)
    blurView.contentView.addSubview(smallHeaderTitle)
    blurView.contentView.addSubview(segmentedControl)
    tableView.tableHeaderView!.addSubview(blurView)

    // add this
    if let v = tableView.tableHeaderView as? SecondaryStretchyTableHeaderView {
        // give our custom header view a reference to the segemented control
        v.segControl = segmentedControl
    }
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    
    guard isUserInteractionEnabled,
          !isHidden,
          alpha >= 0.01,
          let sc = segControl
    else { return nil }

    // if we tap outside the bounds,
    //  but on the segmented control
    //  return the segmented control
    let convertedPoint = sc.convert(point, from: self)
    if let v = sc.hitTest(convertedPoint, with: event) {
        return v
    }
    
    guard self.point(inside: point, with: event) else { return nil }
    
    return self
    
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
    
    cell?.textLabel?.text = String(indexPath.row)
    
    //cell?.layer.zPosition = -1000
    //view.sendSubviewToBack(cell!)
    //view.bringSubviewToFront(tableView.tableHeaderView!)
    
    return cell!
}
//segmentedControl.layer.zPosition = 1000