假设我有3个视图控制器标记为"A","B"和"C".现在,"A"是窗口的rootViewController,当点击按钮时它以模态方式呈现"B".在"B"中,当按下一个按钮时,它应该被"A"解雇,然后"A"将立即以模态方式呈现C.如何做到这一点?这是我希望实现这一目标的代码,但我没有成功.
在"A"viewController中,我声明了一个属性,用于在"B"viewController被"A"解除时,在要调用的头文件中保存一个块.
@property (nonatomic, copy) void (^presentZapLaunch)(void);
Run Code Online (Sandbox Code Playgroud)
这是"A"viewController呈现"B"的现有方法
-(void)presentNextViewCon
{
CYCGestureZapZapViewController *gestureViewCon = [[CYCGestureZapZapViewController alloc]init];
if (!self.presentZapLaunch) {
__weak CYCZapZapViewController *weakRefCon = self;
self.presentZapLaunch = ^{
CYCZapZapViewController *preventWeakRefCon = weakRefCon;
CYCZapZapLaunchViewController *zapLaunch = [[CYCZapZapLaunchViewController alloc]init];
NSLog(@"Called");
[preventWeakRefCon presentViewController:zapLaunch animated:YES completion:nil];
};
}
[self presentViewController:gestureViewCon animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是由"A"解雇的"B"解雇方法,"A"应立即出现"C"
-(void)presentNextViewCon
{
NSLog(@"Hello");
[self.presentingViewController dismissViewControllerAnimated:self completion:^{[(CYCZapZapViewController *)self.presentingViewController presentZapLaunch];}];
}
Run Code Online (Sandbox Code Playgroud)
*请注意,我使用"A"视图控制器作为窗口的rootViewController,"A"以模式方式呈现"B"视图控制器.所有"A","B"和"C"都是视图控制器.
在iOS 7中,此方法没有问题:
_rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[_rootViewController presentViewController:self animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是在iOS 8中它没有做任何事情.如何解决?这是iOS 8的Bug吗?
我有一个xib文件,我在UIView上创建了一个弹出控制器.当在视图控制器1上按下按钮时,此弹出控制器会动画.然后我在UIView上有一个按钮,按下时我想要呈现另一个视图控制器(视图控制器2).代码看起来像:
class PopUpViewControllerSwift : UIViewController {
@IBAction func goToVC2(sender: UIButton) {
self.removeAnimate()
let VC2: VC2 = self.storyboard?.instantiateViewControllerWithIdentifier("VC2") as VC2
var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CoverVertical
VC2.modalTransitionStyle = modalStyle
presentViewController(VC2, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
虽然按下按钮时它会崩溃,没有错误或回调或任何东西.显然,如果它只是一个普通的视图控制器,这通常会起作用,但是因为我在一个弹出的视图中进行了操作,它已经在另一个视图上进行了动画我认为这是问题所在?
有人可以帮忙吗?
谢谢
我想找出一种方法,这样,如果用户按下"取消"按钮(我认为不能删除)ABPeoplePickerNavigationController,视图控制器要么不关闭,要么自动重新打开.
例如,给出以下内容:
var picker = ABPeoplePickerNavigationController()
picker.peoplePickerDelegate = self
self.presentViewController(picker, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我希望能够做到这样的事情:
if (self.presentedViewController != picker && !userContinuedPastPicker) {
//where userContinuedPastPicker is a boolean set to false
//in a delegate method called when the user clicks on an a contact
//(meaning the user didn't press the cancel button but instead clicked on a contact)
//create and present a UIAlertAction informing the user they must select a contact
//present picker again
self.presentViewController(picker, animated: true, completion: nil) …Run Code Online (Sandbox Code Playgroud) uinavigationcontroller abaddressbook ios presentviewcontroller swift
当我从主屏幕使用3D Touch Shortcuts时,我试图转向不同的视图控制器.
应用程序嵌入在一个UITabBarController并且每个选项卡根控制器是一个UINavigationController.
以下是我尝试处理快捷方式以加载每个快捷方式的视图控制器的方法.
private func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) {
if let rootViewController = window?.rootViewController, let shortcutItemType = ShortcutItemType(shortcutItem: shortcutItem) {
let sb = UIStoryboard(name: "main", bundle: nil)
let helloVC = sb.instantiateViewControllerWithIdentifier("HelloVC") as! HelloViewController
let goodbyeVC = sb.instantiateViewControllerWithIdentifier("GoodbyeVC") as! GoodbyeViewController
switch shortcutItemType {
case .Hello:
rootViewController.presentViewController(helloVC, animated: true, completion: nil)
break
case .Goodbye:
rootViewController.presentViewController(goodbyeVC, animated: true, completion: nil)
break
}
}
}
Run Code Online (Sandbox Code Playgroud)
与此代码的快捷方式只打开应用程序初始视图控制器和不将helloVC和goodbyeVC其在不同的选项卡控制器.
我认为这是因为ViewControllers我试图加载嵌入在嵌入的内部UINavigationController以及嵌入内部UITabBarController.
我怎么能presentViewController …
uitabbarcontroller uinavigationcontroller ios presentviewcontroller swift
我只是想知道是否可以在没有动画的情况下显示详细视图控制器(从右侧滑入窗口)。我期望有某种动画布尔参数,但似乎没有。
这就是我所拥有的:
[self.splitViewController showDetailViewController:detailViewController sender:self];
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?或者没有办法做到这一点吗?
cocoa-touch ipad uisplitviewcontroller ios presentviewcontroller
我正试图在我的游戏上创建一个暂停屏幕.我在故事板中添加了一个'PauseScreen'viewController,故事板ID和Restoration ID设置为"PauseScreenID",并移动到暂停屏幕我已在"GameScene"中创建了该功能:
func pauseSceenTransition(){
let viewController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("PauseScreenID") as UIViewController
let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)
currentViewController.window?.rootViewController?.presentViewController(viewController, animated: false, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
但是当它被调用时,我得到错误:
警告:尝试在< AppName .StartScreenViewController:0x7fae61f79980>上显示< AppName .PauseScreen:0x7fae61fe5ff0>,其视图不在窗口层次结构中!
"StartScreenViewController"是我的开始屏幕的视图控制器,是初始视图控制器.然后转到"GameScene",这是"PauseScreen"需要去的地方.如果我将初始视图控制器设置为"GameViewController"/"GameScene",它可以工作,所以我认为我需要更改第二行:
let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)
Run Code Online (Sandbox Code Playgroud)
所以它在"GameViewController"上呈现"PauseScreen",而不是"StartScreenViewController",但我不知道该怎么做.
在多个视图之间切换的最佳做法是什么?更改rootViewController或使用模态视图?
设置rootviewController:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var vc : UIViewController = storyBoard.instantiateViewControllerWithIdentifier("viewTarget") as TargetViewController
var window :UIWindow = UIApplication.sharedApplication().keyWindow!
window.rootViewController = vc;
window.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)
更改模态视图:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("viewTarget") as TargetViewController
self.presentViewController(initViewController,animated: false, nil)
Run Code Online (Sandbox Code Playgroud)
当我需要向用户呈现其他视图时,我很困惑.
ps在我的情况下,我有一个以登录表单开头的应用程序作为rootViewController.登录后,我认为最好改变,rootViewController但我是对的吗?
我有两个观点,我想做一个轻扫样式转换,我已经完成了当有一个segue行动,但我没有在这里,所以我不知道如何应用我的动画类.我班上的所有内容都是:
let stb = UIStoryboard(name: "Walkthrough", bundle: nil)
let walkthrough = stb.instantiateViewControllerWithIdentifier("walk") as! BWWalkthroughViewController
self.presentViewController(walkthrough, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我想申请申请以下自定义segue:
class CustomSegue: UIStoryboardSegue {
override func perform() {
// Assign the source and destination views to local variables.
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!
// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight) …Run Code Online (Sandbox Code Playgroud) 我正在尝试关注最近使用a MPMediaPickerControllerDelegate来呈现音乐选择列表的帖子.
该教程位于以下URL:
http://www.justindoan.com/tutorials/
我正在使用此代码:
import UIKit
import MediaPlayer
class ViewController: UIViewController, MPMediaPickerControllerDelegate {
var mediapicker1: MPMediaPickerController!
override func viewDidLoad() {
super.viewDidLoad()
let mediaPicker: MPMediaPickerController = MPMediaPickerController.self(mediaTypes:MPMediaType.music)
mediaPicker.allowsPickingMultipleItems = false
mediapicker1 = mediaPicker
mediaPicker.delegate = self
self.presentViewController(mediapicker1, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
但是我发现了:
self.presentViewController(mediapicker1, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
不起作用.不幸的是,Swift 3建议的自动解决方案也不起作用:
self.present(mediapicker1, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
此外,iOS 10 Beta发行说明,发现于:
https://www.scribd.com/doc/315770725/IOS-10-Beta-Release-Notes
在第10页,共18页,
MPMediaPickerController对象可能无法按预期显示.
我花了很多时间自己解决这个问题而没有成功.
有什么建议?
mpmediapickercontroller ios presentviewcontroller swift swift3
ios ×7
swift ×7
block ×1
cocoa-touch ×1
ios8 ×1
ipad ×1
objective-c ×1
popup ×1
swift3 ×1
xcode6 ×1