【问题标题】:Switching UIViews from a single XIB从单个 XIB 切换 UIView
【发布时间】:2015-12-27 22:35:43
【问题描述】:

我在本质上翻转 UIView 以模仿卡片翻转时遇到了一点麻烦。

就目前而言,我在 XIB 中创建了两个 UIView(前视图和后视图)并将其加载到情节提要中:

//Initiate the view from the XIB
CustomClass *drag = [[CustomClass alloc] initWithFrame:rect];
//Add the view to the view (container) within the storyboard
[self.draggableView addSubview:drag];

在我的自定义类中如下:

-(id)initWithFrame:(CGRect)frame {
     self = [super initWithFrame:frame];


     self = [[[NSBundle mainBundle] loadNibNamed:@"Draggable"
                                          owner:self
                                        options:nil] objectAtIndex:0];
     return self;
}

这令人满意地呈现了前视图...

现在我无法确定如何翻转视图以在同一个 XIB 中显示另一个 UIView...此 UIView 在“objectAtIndex:1”处可用。

我很确定我需要的代码包括:

[UIView transitionWithView:UIVIEW
                  duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromBottom
                    animations: ^{}];

【问题讨论】:

  • 我们做了什么?

标签: ios objective-c iphone xcode uiview


【解决方案1】:

如果 xib 有很多视图,你应该使用 loadNibNamed 在 xib 文件中创建视图:

 NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"BlueView" owner:nil options:nil];    

     self.blueView = views[0];

     self.yellowView = views[1];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 2017-10-28
    相关资源
    最近更新 更多