我正在更新我的應用程序適用於iOS 8,並增加自動版式約束我的意見。他們大多在工作,但UIScrollView (slideUpScrollView)
給我一些麻煩。裏面有一個UIButton (toggleDrawerButton)
來切換SV的幀。在IB中,有限制條件是將SV保持在底部,高度爲50pts。當按下切換按鈕,它應該改變SV的原點到視圖的頂部,模擬抽屜效果。的iOS 8 - 改變UIScrollView的自動版式與框架啓用
沒有與打開/關閉效果的問題。當我按下toggleDrawerButton,它會產生有時我想,就像在iOS的7(不調用viewDidLayoutSubviews)的影響。其他時候SV會有一個奇怪的效果,其中viewDidLayoutSubviews在我的幀移動後被調用。然後VDLS將嘗試重新約束SV並將ToggleDrawerButton重新設置回原來的關閉位置。當打開抽屜時,這會導致視圖放回底部。似乎是在toggleDrawerButton按下隨機調用VDLS。有時會被調用,其他時間則不會。
我怎樣才能正確地重新定位SV的框架,以實現無自動佈局重新約束它的頂部移動?另外,爲什麼只有在toggleDrawerButton按下時纔會調用VDLS?行爲不一致,這使得難以找到解決方案。
這裏是toggleDrawerButton的動作代碼:
- (void) toggleAddEditDrawer {
if (self.drawerToggle == 0) { // Open the Drawer
self.drawerToggle = 1;
self.itemNameTextField.text = nil;
self.quantityTextField.text = nil;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//Rotate the button and make the SV frame slide up
self.toggleDrawerButton.transform = CGAffineTransformMakeRotation(M_PI/4);
self.slideUpScrollView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
self.slideUpScrollView.contentSize = self.slideUpScrollView.frame.size;
[UIView commitAnimations];
[self.itemNameTextField becomeFirstResponder];
NSLog(@"OPEN Toggle - tableview location is: %@",NSStringFromCGRect(self.tableView.frame));
NSLog(@"OPEN Toggle - scrollview location is: %@",NSStringFromCGRect(self.slideUpScrollView.frame));
NSLog(@"OPEN Toggle - toggleButton location is: %@",NSStringFromCGRect(self.toggleDrawerButton.frame));
} else { //Close the Drawer
self.drawerToggle = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//Reverse the rotation and make the SV frame slide down
self.toggleDrawerButton.transform = CGAffineTransformMakeRotation(0);
self.slideUpScrollView.frame = CGRectMake(0, self.tableView.frame.origin.y + self.tableView.frame.size.height, self.view.frame.size.width, 50);
self.slideUpScrollView.contentSize = self.slideUpScrollView.frame.size;
[UIView commitAnimations];
[self.view endEditing:YES];
NSLog(@"CLOSE Toggle - tableview location is: %@",NSStringFromCGRect(self.tableView.frame));
NSLog(@"CLOSE Toggle - scrollview location is: %@",NSStringFromCGRect(self.slideUpScrollView.frame));
NSLog(@"CLOSE Toggle - toggleButton location is: %@",NSStringFromCGRect(self.toggleDrawerButton.frame));
}
NSLog(@"Drawer Posistion is: %d",self.drawerToggle);
}
編輯:這裏有一些控制檯日誌。
工作幀動畫日誌:
OPEN切換 - 的tableview位置爲:{{0,2},{320,452}}
OPEN切換 - 滾動視圖位置是:{{0,2},{320, 504}}
OPEN切換 - 切換按鈕的位置是:{{128.88730162779191,-6.1126983722080901},{62.225396744416173,62.225396744416173}}
抽屜Posistion是:1個
VDLS幀重新約束日誌:
OPEN切換 - 的tableview位置是:{{0,2},{320,452}}
開到ggle - 滾動視圖位置是:{{0,2},{320,504}}
OPEN切換 - 切換按鈕的位置是:{{128.88730162779191,-6.1126983722080901},{62.225396744416173,62.225396744416173}}
抽屜Posistion是:1
VDLS - toggleButton的位置是:{{0,2},{320,452}}
VDLS - 滾動視圖的位置是:{{0,454},{320,50} {128.88730162779191,-6.1126983722080901},{62.225396744416173,62.225396744416173}}
你得到這個整理出來? – 2014-09-28 02:57:20