【发布时间】: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