写了个demo,建一个Swift文件继承自ScrollingNavigationController,代码如下:
import UIKit
import AMScrollingNavbar
@objcMembers class NavManager: ScrollingNavigationController {
lazy var tableView: UITableView = {
self.view.addSubview($0)
$0.translatesAutoresizingMaskIntoConstraints = false
$0.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
$0.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
$0.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
$0.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0).isActive = true
return $0
}(UITableView())
func configFollowScrollView(_ scrollableView: UIView, delay: Double = 0, scrollSpeedFactor: Double = 1, collapseDirection: NavigationBarCollapseDirection = .scrollDown, additionalOffset: CGFloat = 0, scrollSearchBar: Bool = false, followers: [NavigationBarFollower] = []) {
self.followScrollView(scrollableView, delay: delay, scrollSpeedFactor: scrollSpeedFactor, collapseDirection: collapseDirection, additionalOffset: additionalOffset, scrollSearchBar: scrollSearchBar, followers: followers)
}
}
然后建一个OC分类NavManager+Extension,代码如下:
#import <Foundation/Foundation.h>
@interface NavManager (Extension)
@end
#import "NavManager+Extension.h"
#import "NavbarDemo-Swift.h"
@implementation NavManager (Extension)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self configFollowScrollView:self.tableView delay:0 scrollSpeedFactor:1 collapseDirection:NavigationBarCollapseDirectionScrollDown additionalOffset:0 scrollSearchBar:true followers:nil];
}
@end
Build 成功,你可以参考一下。
Objective-C继承Swift类搜到的相关资料基本来自这个帖子Inherit from a Swift class in Objective C[https://stackoverflow.com/ques...