首先需要子类化一个navigationController的子类,在init方法中对定制nav的一些基本需求进行设置
1 - (instancetype)initWithRootViewController:(UIViewController *)rootViewController
2 {
3 if (self = [super initWithRootViewController:rootViewController]) {
4 // 设置navigationBar的背景颜色,根据需要自己设置
5 self.navigationBar.barTintColor = redButtonColor;
6 // 设置navigationBar是否透明,不透明的话会使可用界面原点下移(0,0)点为导航栏左下角下方的那个点
7 self.navigationBar.translucent = NO;
8 // 设置navigationBar是不是使用系统默认返回,默认为YES
9 self.interactivePopGestureRecognizer.enabled = YES;
10 // 创建一个颜色,便于之后设置颜色使用
11 UIColor * color = [UIColor whiteColor];
12 // 设置navigationBar元素的背景颜色,不包括title
13 self.navigationBar.tintColor = color;
14 // 设置navigationController的title的字体颜色
15 NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];16 self.navigationBar.titleTextAttributes = dict;
17 }
18
19 return self;20 }
因为这个导航栏是你自己自定义的,所以默认的侧滑返回会失效,接下来要在viewDidLoad中从新遵循手势的代理
- (void)viewDidLoad
{ // 为self创建弱引用对象
__weak typeof (self) weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
}
转载于:https://my.oschina.net/u/2435028/blog/550096
分享到:
相关推荐
iOS-7-Custom-ModalViewController-Transitions, 在 iOS 7中,实现新的自定义ModalViewController转换的示例项目 iOS-7-Custom-ModalViewController-Transitions在 iOS 7上实现新定制ModalViewController过渡的示例...
在iOS应用开发中,自定义导航栏(Custom NavigationController)是一项常见的需求,它允许开发者根据应用的风格和品牌定制导航栏的外观和行为。在Swift 5.2中,我们可以利用Apple提供的UIKit框架来实现这一功能。这...
self.navigationController.navigationBar.layer.addSublayer(customLayer) ``` 4. **监听滚动事件**:我们需要监听UITableView或UICollectionView的滚动事件,例如`scrollViewDidScroll:`方法。在滚动回调中,...
let leftButton = UIButton(type: .custom) leftButton.frame = CGRect(x: 0, y: 0, width: 60, height: 40) leftButton.setTitle("返回", for: .normal) leftButton.setImage(UIImage(named: "UINavigationBar.png...
加入收藏applidium / ADTransitionController Star 712Fork 88UINavigationController with custom transitionsupdate at 2014-10-13介绍: ADTransitionController实现多种视图切换动画。包括滑动、旋转、淡出、...
wid_ctrl.custom_msg = @"请扫瞄离您最近的iMall二维码,以获取到目的地的路线"; NSMutableSet *readers = [[NSMutableSet alloc] init]; QRCodeReader *qrcode_reader = [[QRCodeReader alloc] init]; [readers...
通过设置`navigationController(_:animationControllerFor:)`和`navigationController(_:interactionControllerFor:)`方法,你可以为导航控制器指定自定义的动画和交互控制器。 5. **CAAnimation** 和 **CALayer**...
5. **Custom Transition**:为了实现平滑过渡效果,开发者可能会自定义视图控制器间的转场动画,这涉及到UIView动画或CAAnimation的相关知识。 6. **SegmentedControl** 或 **Paging** 效果:这两个组件可以作为...
在iOS开发中,自定义转场动画是...对于`UINavigationController`的转场动画,我们可以通过重写`navigationController:animationControllerForOperation:fromViewController:toViewController:`和`navigationController:...
[self.navigationController.view addSubview:_sheet]; [_sheet showAnimation]; //显示动画 #pragma mark - Custom Deledate - (void)actionSheetDidFinished:(NSArray *)obj{ NSLog(@"已发送 %lu 图片",...
- 对于`UINavigationController`,我们可以设置其`delegate`属性,并实现`UINavigationControllerDelegate`协议中的`navigationController(_:animationControllerFor:)`和`navigationController(_:...
开发者CDchendong在这个项目中实现了一个自定义的导航控制器(NavigationController),并结合手势识别(Gesture Recognizer)和视图动画(View Animation)来实现滑动手势与导航栏状态变化的联动。 1. 自定义导航...
let navigationController = UINavigationController(rootViewController: rootViewController) ``` 在Storyboard中,可以通过拖拽`UINavigationController`到场景中,并将需要的初始视图控制器设置为其根视图控制...
8. **Custom Transitions**: 如果想要模仿QQ的滑动过渡效果,可能需要自定义转场动画。SwiftUI提供了`transition`修饰符,配合`onAppear`和`onDisappear`等生命周期方法,可以创建自定义的视图进入和退出动画。 9. ...
.navigationBar.barTintColor = UIColor.customColor self.navigationItem.titleView = customTitleView // 其他自定义设置 } } ``` 4. **利用`UINavigationItem`和`UIBarButtonItem`**:创建自定义的`...
- `type`:定义了按钮的样式,如`UIButtonType.system`、`UIButtonType.custom`等。 - `action`:关联的点击事件处理方法。 在实际项目中,我们通常会通过`addTarget(_:action:for:)`方法为按钮添加点击事件处理: ...
CustomViewController *viewController = [[CustomViewController alloc ] init ]; [viewController pushIt ]; [ MKTVerify (viewController.navigationController) pushViewController: anything () animated: ...
每个标签对应一个Tab项,每个Tab项都可以有自己的NavigationController,实现更复杂的视图结构。 3. **UIPageViewController**: UIPageViewController用于创建翻页效果,适合于展示类似电子书或相册的应用。通过...