iOS - 跨故事板使用的NIB视图(用于设计和动画逻辑) [英] iOS - a NIB's view used across storyboards (for design & animation logic)

查看:94
本文介绍了iOS - 跨故事板使用的NIB视图(用于设计和动画逻辑)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS 5项目差不多完成了,但是到处都有一个View缺失了。它是标准NavigationBar的替代品,您可以通过滑动在导航层次结构中返回,并且可以很好地进行动画制作。

I have a iOS 5 project nearly completed, but there's one View missing everywhere which is the same. It's an alternative to the standard NavigationBar, you can go "back" in the navigation hierarchy with a swipe and it's animating nicely.

好的,因为布局很难做到通过代码我创建了空的IB文档(HeaderView.xib),其中我有一个包含子视图等的视图。
之前我有动画代码所以我刚刚创建了一个UIView子类(HRAnimationView)(并且写了名字它在xib的检查员自定义类字段中,也通过方法将子视图连接到出口):

Ok, because it's hard to do the layout by code I created the empty IB document (HeaderView.xib) where I have a view containing subview and etc. I had the animation code before so I just created a UIView subclass ("HRAnimationView") (and wrote the name of it in the xib's inspectors "Custom Class" field, also hooked up the subviews to outlets) with a method:

- (void)loadAnimation {…}

和第二个(这是完成动画的委托方法) :

and a second one (this is the delegate-method for finished animations):

- (void)animationDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {}

...这是所有动画内容发生的地方,一遍又一遍地调用自己,直到它为止完成...

...this is where all the animation stuff happens and calling itself over and over till it's finished...

在我的故事板中具有完全相同尺寸(及其出口)的子视图,并希望加载XIB(在相应控制器的viewDidLoad方法中):

In the storyboard I have a subview with exact the same dimensions (and the outlet for it) and wanted to load the XIB (in the viewDidLoad-method of the corresponding controller) with:

NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];

HRAnimationView *view;

for (id object in bundle) {        
    NSLog(@"%@",object);
    if ([object isKindOfClass:[UIView class]])
        view = (HRAnimationView *)object;
}

self.headerView = view;
[self.view setNeedsDisplay];
[view loadAnimation];

但是headerView是EMTPY !! (也是UIView *视图没有用,也没有所有者:self.headerView)

BUT the headerView is EMTPY!! (also UIView *view didn't worked, nor owner:self.headerView)

...日志只是给了我:

…the Log just gives me:

<HRAnimationView: 0x3f1890; frame = (0 0; 240 49); autoresize = RM+BM; layer = <CALayer: 0x3f18d0>>

...

这是什么问题? ?也没有编译失败!

WHAT IS the problem?? There's also no compilation failure!

我不明白,为什么xib在我的情况下完全没用?!

I don't get it, why is the xib TOTALLY worthless in my case?!

推荐答案

已解决!!!

我创建了一个新的ViewController并检查了使用xib创建框并删除了xib和copy& amp的视图;粘贴已经设置好的视图,在ViewController中我把动画代码放在viewDidLoad中。

I created a new ViewController and checked the "create with xib" box and deleted the view of the xib and copy&pasted the already set up view in there and in the ViewController I put the animation code in viewDidLoad.

然后在每个故事板ViewController的viewDidLoad方法中加载了一个洞穴with:

Then loaded the hole thing in the viewDidLoad-method of each storyboard ViewController with:

UIViewController *ctrl = [[UIViewController alloc] initwithNibNamed:@"HeaderView"];
[self.headerView addSubview:ctrl.view]

(headerView是一个IBOutlet到一个在每个故事板中查看,这基本上是唯一要设置的东西,NICE!)

(headerView is a IBOutlet to a view in every Storyboard so, that's basically the only thing to setup, NICE!)


  1. 另一种可能性是:
    使用没有外部xib的storyboard添加子视图

  2. 或: http://forums.macrumors.com/showthread.php?t= 749544

  1. another possibility would be: Add subview using storyboard without external xib
  2. or: http://forums.macrumors.com/showthread.php?t=749544

看起来没有相应的ViewController,Xib是没用的,但应该(奇怪......等等)。
但是感谢您的回复,希望有人现在可以找到这个,如果他/她有同样的问题!

Looks like a Xib is useless without a corresponding ViewController, but should (strange.. whatever). But thanks for your responses, hope someone now can find this if he/she has the same problem!

这篇关于iOS - 跨故事板使用的NIB视图(用于设计和动画逻辑)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆