【问题标题】:Moving containerView in superView as a subview将superView中的containerView作为子视图移动
【发布时间】:2015-02-04 13:58:13
【问题描述】:

下图描述了该场景。 http://i.stack.imgur.com/PPm4e.png

按下动画按钮时,蓝屏(或 containerView)应远离视图,并在按下时同样返回初始位置。

代码正在运行。但是 containerView 的行为并不像其他视图的子视图。它不应该出现在浅灰色的视图中。这是它的超级观点。它应该在其范围内上下移动。

模拟器截图如下:

http://i.stack.imgur.com/SJjA5.png

http://i.stack.imgur.com/I98W8.png

非常感谢任何建议。

ViewController.m :-

@interface ViewController ()
{
    BOOL scrollUp;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self.containerBackgroundView addSubview:self.containerview];

    scrollUp = NO;
    [self animate:self];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

}


- (IBAction)animate:(id)sender {

    if (scrollUp) {
        [self rollUpMenuPage];
        scrollUp = NO;
    }
    else
    {
        scrollUp = YES;
        [self unRollTheMenuPage];
    }

}

-(void)unRollTheMenuPage
{

    NSLog(@"containerview frame before unRoll : %@",[self.containerview description]);

    CGRect rect = CGRectMake(self.containerview.frame.origin.x, 0.0f, self.containerview.frame.size.width, self.containerview.frame.size.height);


    [UIView animateWithDuration:1.0f
                     animations:^{

                         self.containerview.frame = rect;
                     }
                     completion:^(BOOL finished){
                         // do something here if you wish.

                         NSLog(@"containerview frame after unRoll : %@",[self.containerview description]);

                     }];

}

-(void)rollUpMenuPage
{

    NSLog(@"containerview frame before roll up : %@",[self.containerview description]);

    CGRect rect = CGRectMake(self.containerview.frame.origin.x, -self.containerBackgroundView.frame.size.height, self.containerview.frame.size.width, self.containerview.frame.size.height);


    [UIView animateWithDuration:1.0f
                     animations:^{
                         self.containerview.frame = rect;
                     }
                     completion:^(BOOL finished){

                         NSLog(@"containerview frame after roll up : %@",[self.containerview description]);

                     }];


}

ViewController.h

@property (weak, nonatomic) IBOutlet UIView *containerBackgroundView;
@property (weak, nonatomic) IBOutlet UIView *containerview;

当前输出:- http://screencast.com/t/bfLmJFYmym4

问题是,向上移动时,它不应超过浅灰色视图。

谢谢

【问题讨论】:

  • 显示您用于制作动画的代码
  • 抱歉我不知道如何添加代码
  • 你在文本区域上方有一个“{}”的标志,写下任何文本并全选并按下按钮“{}”
  • 非常感谢,@YuviGr
  • 什么是上白视图?是containerBackgroundView的子视图吗?

标签: ios objective-c iphone


【解决方案1】:

好的,在重新创建您的项目并对其进行测试后,您在 superView 边界之外绘制的视图是正确的。

要撤消此操作,您可以单击后视图中的clip subviews 属性,因此当 containerView 超出 backView 边界时,它将被剪裁并且不会被绘制

【讨论】:

  • 他没有在他在那里构建的矩形中为 origin.y 设置负值,那么为什么它会超出另一个视图的顶部?
  • 我相信“-self.containerBackgroundView.frame.size.height”是一个负值。
  • @YuviGr,早上好,是的,“-self.containerBackgroundView.frame.size.height”是一个负值,只是为了确保它向上移动。
【解决方案2】:

在我看来,您在顶部添加了一个 UINavigationBar(或其他一些工具栏)作为 UIViewController 视图的子视图,并且 containerBackroundView(透明 bg 颜色)位于该栏的顶部。 建议您更改 containerBackgroundView 的 frame.origin.y,使其不会覆盖那里的顶部栏或状态栏下方。

【讨论】:

  • 谢谢,但我没有在顶部添加任何导航栏或任何内容。它只包含一个 ViewController,甚至没有嵌入任何导航控制器中。
  • 状态栏上下的白色矩形是什么?蓝色文本 def 看起来像 UINavigationItem..
猜你喜欢
  • 2014-07-15
  • 1970-01-01
  • 1970-01-01
  • 2015-06-30
  • 2020-08-18
  • 2018-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多