下图描述了该场景。 http://i.stack.imgur.com/PPm4e.png
按下动画按钮时,蓝色屏幕(或容器视图)应远离视图,同样会在压制时返回初始位置。
代码正在运行。但是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
问题是,当向上移动时,它不应超过浅灰色视图。
由于
答案 0 :(得分:0)
在我看来,你已经添加了一个UINavigationBar(或其他一些工具栏)作为UIViewController视图的子视图,而containerBackroundView(透明的bg颜色)位于该栏的顶部。 建议你改变containerBackgroundView的frame.origin.y,这样它就不会覆盖那里的顶栏或者在状态栏下方。
答案 1 :(得分:0)
好的,在重新创建项目并进行测试之后,你就可以在它的超级视图边界之外绘制视图了。
要撤消此操作,您可以单击后视图中的clip subviews
属性,因此当containerView跳出backView边界时,它将被剪切并且不会被绘制