- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我打算使用 UINavigationController
创建一个应用程序来呈现下一个 View Controller 。在 iOS5 中,有一种呈现 UIViewControllers
的新方法:
presentViewController:animated:completion:
现在我问我为什么 UINavigationController
没有完成处理程序?只有
pushViewController:animated:
是否可以创建我自己的完成处理程序,如新的 presentViewController:animated:completion:
?
最佳答案
参见 par's answer获取另一个更新的解决方案
UINavigationController
动画与 CoreAnimation
一起运行,因此将代码封装在 CATransaction
中并因此设置一个完成 block 是有意义的。
swift :
对于swift,我建议创建一个这样的扩展
extension UINavigationController {
public func pushViewController(viewController: UIViewController,
animated: Bool,
completion: @escaping (() -> Void)?) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
pushViewController(viewController, animated: animated)
CATransaction.commit()
}
}
用法:
navigationController?.pushViewController(vc, animated: true) {
// Animation done
}
objective-C
标题:
#import <UIKit/UIKit.h>
@interface UINavigationController (CompletionHandler)
- (void)completionhandler_pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)(void))completion;
@end
实现:
#import "UINavigationController+CompletionHandler.h"
#import <QuartzCore/QuartzCore.h>
@implementation UINavigationController (CompletionHandler)
- (void)completionhandler_pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)(void))completion
{
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self pushViewController:viewController animated:animated];
[CATransaction commit];
}
@end
关于ios - UINavigationController "pushViewController:animated"的完成处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9906966/
我想为我的 View 设置动画以响应用户操作,使其看起来像 pushviewcontroller 的动画。也就是说,我希望 View 响应用户操作从屏幕向左滑动。但是,我不想创建一个新 View 并使
如何从 tabBarController 和 navigationController 切换到新 View ,并且新 View 中没有 tabBar 和 navigationBar?我需要向右滑动才能
这是我第一次尝试使用 UINavigationController 实现从一个 tableView 单元格到另一个 tableView 的导航,它对我不起作用。我没有使用 nib 文件,我有一个简单的
推送到堆栈上的 View Controller 不能是选项卡栏 Controller 的实例,并且它不能已经在导航堆栈上。 我想知道我如何发现我即将插入堆栈的 View Controller 是否已经
我想做的是从左侧插入ViewController的自定义动画。我已经创建了自定义过渡委托(delegate),并提供了自定义动画,一切正常(新 View 从左侧幻灯片)。唯一的问题是 iOS 中的推送
我有一个 SidebarMenueController,它是启动应用程序后的入口点。在其中我有一个嵌入侧边栏(滑出)菜单的导航 Controller 。使用 sideBarDidSelectButto
viewcontroller 上有一个按钮,当我单击 按钮 pushviewcontroller 不起作用。 我的 appdelegate.m 文件: - (BOOL)applicationUIApp
我想知道是否可以在没有标签栏和导航栏的情况下全屏推送 NavigationController 的 ViewController。我的问题如下: 我的应用在 TabBarController 中嵌入了
我使用此代码来呈现 UIviewController: -(IBAction)openWoodenPage3:(id)sender{ UIStoryboard *storyboard = [UISto
这是我在网上获得的代码,它确实适用于我之前开发的项目。但是在这个项目中,当我 NSLog 它时,self.navigationController 为 null ,网上的人讨论过在委托(delegat
我正在尝试完成一些非常简单的事情。当我的 Collection View 中的唯一项目被推送时,我试图以编程方式推送到 viewController。什么都没发生。我相信在我纠结的一团糟中有不止一个问
我有一个导航 Controller 、一个 View Controller 和一个 TableView ,它们都是在我的 Storyboard中创建的: 当您触摸 TableView 中的某一行时,它
在 iPhone 应用程序中,我希望在根导航 Controller 的导航栏右侧有一个导航按钮。但是,每次我将另一个 viewController 推到导航 Controller 顶部并且右侧插槽变空
我在 appDelegate 中设置了 navigationController,但现在我在另一个 ViewController 中记忆起它,但它不起作用。这是我的代码: 在appDelegate.h
我有三个 View Controller 。 MainViewController、secondViewController、thirdViewController。我想知道一旦我点击 thirdVi
我对 Objective-C 和 iPhone 编程还很陌生,所以如果这是一个新手问题,我深表歉意。我有一个简单的应用程序,需要从一个 View 转到另一个 View 。第一个 View 是 UIVi
我正在做基于 View 的应用程序,我已经添加了表格 View 。现在我已经在 didSelectRowAtIndexPath 方法中编写如下,当用户点击一行然后导航到“learncourse”nib
我正在尝试推送 ViewController,但我的应用程序每次都会崩溃。 我正在使用 UIImagePickerControllerDelegate 拍照,一旦拍照,这段代码就会运行: func i
我在一个按钮中做了一个推送功能: @IBAction func prodButton(sender: AnyObject) { let storyboard = UIStoryboard(na
我是 IOS 的新手。我所做的只是简单地在我的主视图上放置一个 UIButton,我希望当我单击该按钮时它应该将我带到下一个堆栈。为此,我正在做的是 -(IBAction)stack:(id)send
我是一名优秀的程序员,十分优秀!