简体   繁体   English

在superView中将containerView作为子视图移动

[英]Moving containerView in superView as a subview

following image describes the scenario. 下图描述了该场景。 http://i.stack.imgur.com/PPm4e.png http://i.stack.imgur.com/PPm4e.png

On animate button press, the blue screen (or containerView) should move away from view and similarly come back to initial position on repress. 按下动画按钮时,蓝屏(或containerView)应移离视图,并且类似地回到按下时的初始位置。

The code is working. 该代码正在运行。 But the containerView is not behaving as the subview of some other view. 但是containerView不能作为其他视图的子视图。 It should not come out of light gray colored view. 它不应来自浅灰色的视图。 Which is its super view. 这是它的超级视图。 It should move up and down within its limits. 它应该在其范围内上下移动。

The simulator screen shots are as follows : 模拟器的屏幕截图如下:

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

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

Any suggestions are highly appreciated. 任何建议都将受到高度赞赏。

ViewController.m :- 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 ViewController.h

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

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

Issue is, when moving up it should not go above the light gray colored view. 问题是,向上移动时,它不应超出浅灰色视图上方。

Thanks 谢谢

It looks to me like you have added a UINavigationBar (or some other toolBar) up top as a subview of your UIViewController's view, and that containerBackroundView (which is transparent bg colour) is over the top of that bar. 在我看来,您似乎在顶部添加了一个UINavigationBar(或其他一些ToolBar)作为UIViewController视图的子视图,并且那个containerBackroundView(透明bg色)在该栏的顶部。 Suggest you alter the frame.origin.y of containerBackgroundView so that it does not cover that top bar there or go beneath the status bar. 建议您更改containerBackgroundView的frame.origin.y,以使其不覆盖顶部栏或位于状态栏下方。

Ok, after re-creating your project and testing it you are right the view si drawn outside of it's superView bounds. 好的,在重新创建项目并对其进行测试后,您将在SuperView边界之外绘制的视图正确。

To undo this you can click the clip subviews property in the back view, so when the containerView steps out of the backView bounds it will be clipped and will not get drawn 要撤消此操作,可以单击后clip subviews中的clip subviews属性,因此,当containerView超出backView边界时,它将被裁剪并且不会被绘制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM