寫了個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類搜到的相關(guān)資料基本來自這個帖子Inherit from a Swift class in Objective C[https://stackoverflow.com/ques...