我使用容器 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];
}
Best Answer-推荐答案 strong>
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/
|