我会告诉你一个屏幕截图,但我没有足够的声誉(我曾经遇到的其他问题我可以找到其他人的帖子).
它甚至会显示带有填充点的圆圈,单击时会显示正确的按钮.在连接检查器中,它在发送的事件下显示“Touch Up Inside”和“UserPage btnProgressClick”之间的连接(Userpage是我的类,它扩展了UIViewController并被这个微粒View Controller引用,btnProgressClick是我想要的IBAction函数的名称跑).
我找到了this post,我尝试了一个干净的构建但是没有用.我也移动了我的按钮,它在模拟器中正确更新.
btnProgressClick中的代码永远不会执行.我在第一行放了一个断点,它没有断开.
这是将按钮链接到函数的“Main.storyboard”XML代码.
<!--User Page--> <scene sceneID="aNb-aX-hZF"> <objects> <viewController storyboardIdentifier="UserPage" id="w2h-zR-Kdu" customClass="UserPage" customModule="GenomeTrackerDemo" customModuleProvider="target" sceneMemberID="viewController"> <layoutGuides> <viewControllerLayoutGuide type="top" id="9dS-Hw-ZYg"/> <viewControllerLayoutGuide type="bottom" id="7PS-pA-lFe"/> </layoutGuides> <view key="view" contentMode="scaleToFill" id="w6A-eT-aKv"> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JGD-xx-tMQ"> <rect key="frame" x="20" y="48" width="46" height="30"/> <state key="normal" title="Button"/> <connections> <action selector="btnProgressClick:" destination="w2h-zR-Kdu" eventType="touchUpInside" id="F1N-QY-fhb"/> </connections> </button> </subviews> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> </view> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="Fsq-L4-Are" userLabel="First Responder" sceneMemberID="firstResponder"/> </objects> <point key="canvasLocation" x="1043" y="426"/> </scene>
这是UserPage类:
import Foundation import UIKit class UserPage: UIViewController { var thisUser: User = User() override func viewDidLoad() { super.viewDidLoad() } @IBAction func btnProgressClick(sender: UIButton) { let storyboard = UIStoryboard(name: "Main",bundle:nil) let vc: progressPage = storyboard.instantiateViewControllerWithIdentifier("progressPage") as! progressPage UIView.transitionFromView(self.view,toView: vc.view,duration: 0.8,options: UIViewAnimationOptions.TransitionFlipFromRight,completion: nil) } }
正如我之前所说,这是我的第一个问题,所以我愿意接受有关措辞如何以及我提供的信息的反馈.
我想添加一些有关如何调用此页面的信息.在对Web服务进行异步调用之后调用它.数据成功恢复后,我转换到具有此功能的页面:
func afterSuccessfulLogin(thisUser: User){ dispatch_async(dispatch_get_main_queue()){ let storyboard = UIStoryboard(name: "Main",bundle:nil) let vc: UserPage = storyboard.instantiateViewControllerWithIdentifier("UserPage") as! UserPage vc.thisUser = thisUser UIView.setAnimationCurve(.EaseIn) UIView.transitionFromView(self.view,duration: 1.2,completion: nil) } }
不确定这是否有所作为,但我想我会把它扔在那里.
对此问题的任何帮助都非常有用.
谢谢!!
解决方法
iOS包含视图层次结构和视图控制器层次结构.这两者都需要保持一致.在问题中发布的代码中,仅处理视图层次结构.请尝试以下更改:
>在调用transitionFromView之前调用addChildViewController:on self:toView:duration:options:completion:传递vc.
>在transitionFromView的完成块中:toView:duration:options:completion:方法,调用didMoveToParentViewController:on vc,传递self.
let storyboard = UIStoryboard(name: "Main",bundle:nil) let vc: UserPage = storyboard.instantiateViewControllerWithIdentifier("UserPage") as! UserPage vc.thisUser = thisUser UIView.setAnimationCurve(.EaseIn) self.addChildViewController(vc) UIView.transitionFromView(self.view,completion: { (finished) -> Void in vc.didMoveToParentViewController(self) })
调用transitionFromView:toView:duration:options:completion:并将self.view作为fromView参数传递也有点奇怪.通常会删除fromView参数并将其替换为toView参数,该参数会使视图控制器层次结构中的原始视图控制器在视图层次结构中没有实际视图.引入要替换的嵌套UIView而不是self.view可能是明智之举.