[英]Moving containerView in superView as a subview
下圖描述了該場景。 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
問題是,向上移動時,它不應超出淺灰色視圖上方。
謝謝
在我看來,您似乎在頂部添加了一個UINavigationBar(或其他一些ToolBar)作為UIViewController視圖的子視圖,並且那個containerBackroundView(透明bg色)在該欄的頂部。 建議您更改containerBackgroundView的frame.origin.y,以使其不覆蓋頂部欄或位於狀態欄下方。
好的,在重新創建項目並對其進行測試后,您將在SuperView邊界之外繪制的視圖正確。
要撤消此操作,可以單擊后clip subviews
中的clip subviews
屬性,因此,當containerView超出backView邊界時,它將被裁剪並且不會被繪制
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.