iphone - UIView过渡动画不显示 subview

标签 iphone ios uiview uiviewanimationtransition

我使用容器 View 作为两个 subview 的 super View 。我想将一个 subview “翻转”到另一个 subview 。第一个 subview 恰好是空白的,第二个 subview 是一个包含一些文本的 UILabel。

翻转正在发生,但我看不到我的 subview 。

我想将 blankLabelView 转换为 labelToTransition。有任何想法吗?谢谢!

代码:

-(void)viewDidLoad {
    CGRect labelFrame = CGRectMake(100.0, 217.0, 125.0, 34.0);

    self.labelContainerView = [[UIView alloc] initWithFrame:labelFrame];
    // If I change the background color to something other than clear
    // I can see that this view is flipping, otherwise it appears that
    // nothing happens.
    self.labelContainerView.backgroundColor = [UIColor clearColor];
    [self.someSuperview addSubview:self.labelContainerView];

    UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
    label.backgroundColor = [UIColor clearColor];
    label.lineBreakMode = UILineBreakModeWordWrap;
    label.numberOfLines = 2;
    label.textAlignment = UITextAlignmentCenter;
    self.labelToTransition = label;

    UIView *blankView = [[UIView alloc] initWithFrame:labelFrame];
    blankView.backgroundColor = [UIColor clearColor];
    self.blankLabelView = blankView;
}

-(void)viewWillAppear {
   self.labelToTransition.text = @"some text from a model object";

   [self.labelContainerView addSubview:self.blankLabelView];
}

-(void)flipViewAnimation {
    UIView *containerView = self.labelContainerView;

    [UIView transitionWithView:containerView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromBottom 
                animations:^{ 
                    [self.blankLabelView removeFromSuperview];
                    [containerView addSubview:self.labelToTransition];
                }
                completion:NULL];
}

最佳答案

可能UILabel的框架设置不正确

尝试

CGRect labelFrame = CGRectMake(0, 0.0, 125.0, 34.0);

对于翻转功能,请尝试以下代码片段

-(void)LetUsFlip
{
[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];  
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:flipContainerView cache:YES];

    if ([self.blankLabelView superview])
    {
        [self.blankLabelView removeFromSuperview];
        [self.labelContainerView addSubview:self.labelToTransition];
        [self.labelContainerView sendSubviewToBack:self.blankLabelView];
    }
    else
    {
        [self.labelToTransition removeFromSuperview];
        [self.labelContainerView addSubview:self.blankLabelView];
        [self.labelContainerView sendSubviewToBack:self.labelToTransition];
    }

    [UIView commitAnimations];
}

关于iphone - UIView过渡动画不显示 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8690829/

相关文章:

iphone - 如何在ios5中每30秒在后台运行我的应用程序一次?

iphone - 如何为 iPhone 应用程序创建一个带有兴趣点的旋转地球仪?

iOS 如何为每个目标创建配置文件

iPhone:如何构建自己的 TabBar?

iphone - 将图像从一个 View 设置为另一个 xcode 4.4

iphone - PhoneGap openDatabase() 方法在 iPhone/iPad 4.x 应用程序中返回 null

iphone - Xcode:在现有项目中找不到库文件,它应该在哪里?

ios - 在 iOS 中使用 GCD 实现临界区

ios - Swift 3/iOS UIView 在检索远程 JSON 数据后不更新

iphone - 部分剪辑 subview