旋轉後我的視圖的大小重置有一些小問題,我無法修復它。旋轉後重新初始化UIView視圖和子視圖
我在我的視圖「bottomContainerView」上放了一個「滑動」動作,大小根據方向而不同!
這裏是我的新代碼:
-(void)swipeToggle:(UISwipeGestureRecognizer *)sender {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
if (sender.direction == UISwipeGestureRecognizerDirectionUp){
NSLog(@"if gesture up - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, 480.0, 300.0);}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
} else if (sender.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"else if gesture down - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 84.0, 480.0, 216.0);}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
if (sender.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"if gesture down - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 640.0);
}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
else if (sender.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"else if gesture up - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 244.0, self.view.frame.size.width, 216.0);
}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
}
更新的Post - 這是我的新代碼正確與你教會了我什麼,並親切地解釋;-)
你的動畫代碼亂七八糟。爲什麼在基於塊的動畫中使用commitAnimations/beginAnimations? – Abizern
只是因爲我是新手!但也許你可以向我解釋爲什麼我做錯了,如何做得更好而不是批評? – GilbertOOl
特別是因爲你似乎是一個不錯的偉大的ios開發者! – GilbertOOl