我有一個視圖,它應該在縱向和橫向模式下有不同的佈局。我實現了一個方法來重繪我的UI元素與自動調整大小(無自動版式):表格單元在旋轉後不可選
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
[self buildViewElements:UIInterfaceOrientationMaskPortrait duration:duration];
break;
case UIInterfaceOrientationPortraitUpsideDown:
[self buildViewElements:UIInterfaceOrientationMaskPortrait duration:duration];
break;
case UIInterfaceOrientationLandscapeLeft:
[self buildViewElements:UIInterfaceOrientationMaskLandscape duration:duration];
break;
case UIInterfaceOrientationLandscapeRight:
[self buildViewElements:UIInterfaceOrientationMaskLandscape duration:duration];
break;
default:
break;
}
}
的方法getLargestAttributeOfSize:
-(void)buildViewElements:(UIInterfaceOrientationMask)interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationMaskPortrait) {
NSLog(@"Portrait");
[UIView animateWithDuration:duration animations:^{
CGRect newImageFrame = CGRectMake(20, 15, 100, 100);
_personImage.frame = newImageFrame;
CGRect newNameLabelFrame = CGRectMake(128, 20, 172, 21);
_nameLabel.frame = newNameLabelFrame;
CGRect newNameDescFrame = CGRectMake(128, 41, 172, 21);
_nameDescriptionLabel.frame = newNameDescFrame;
CGRect newBorrowedFrame = CGRectMake(128, 64, 75, 21);
_borrowedLabel.frame = newBorrowedFrame;
CGRect newBorrowedValueFrame = CGRectMake(211, 64, 42, 21);
_borrowedValueLabel.frame = newBorrowedValueFrame;
CGRect newLendFrame = CGRectMake(128, 93, 75, 21);
_lendLabel.frame = newLendFrame;
CGRect newLendValueFrame = CGRectMake(211, 93, 42, 21);
_lendValueLabel.frame = newLendValueFrame;
CGRect newcontainerFrame = CGRectMake(0, 130, 320, [CNX_Tools getLargestAttributeOfSize:[[UIScreen mainScreen] bounds].size] - 194);
_tableContainerView.frame = newcontainerFrame;
CGRect newDetailFrame = CGRectMake(20, 0, 280, 29);
_detailSelector.frame = newDetailFrame;
CGRect newTableFrame = CGRectMake(0, 36, 320, newcontainerFrame.size.height - 39);
_tableView.frame = newTableFrame;
}];
}
else if (interfaceOrientation == UIInterfaceOrientationMaskLandscape) {
NSLog(@"Landscape");
[UIView animateWithDuration:duration animations:^{
CGFloat factor = 1.0f;
CGFloat diff = 0.0f;
if ([CNX_Tools getLargestAttributeOfSize:[[UIScreen mainScreen] bounds].size] <= 480) {
// iPhone4 size
factor = 0.8f;
diff = 10.0f;
}
CGRect newImageFrame = CGRectMake(75*factor-diff, 20, 100, 100);
_personImage.frame = newImageFrame;
NSLog(@"Bild Frame %f", newImageFrame.origin.x);
CGRect newNameLabelFrame = CGRectMake(20, 140, 210*factor, 21);
_nameLabel.frame = newNameLabelFrame;
CGRect newNameDescFrame = CGRectMake(20, 161, 210*factor, 21);
_nameDescriptionLabel.frame = newNameDescFrame;
CGRect newBorrowedFrame = CGRectMake(20, 184, 75, 21);
_borrowedLabel.frame = newBorrowedFrame;
CGRect newBorrowedValueFrame = CGRectMake(103, 184, 42, 21);
_borrowedValueLabel.frame = newBorrowedValueFrame;
CGRect newLendFrame = CGRectMake(20, 213, 75, 21);
_lendLabel.frame = newLendFrame;
CGRect newLendValueFrame = CGRectMake(103, 213, 42, 21);
_lendValueLabel.frame = newLendValueFrame;
CGRect newContainerFrame = CGRectMake(250*factor, 0, [CNX_Tools getLargestAttributeOfSize:[[UIScreen mainScreen] bounds].size] - 250*factor, 268);
_tableContainerView.frame = newContainerFrame;
CGRect newDetailFrame = CGRectMake(20, 10, newContainerFrame.size.width - 40 , 29);
_detailSelector.frame = newDetailFrame;
CGRect newTableFrame = CGRectMake(0, 49, newContainerFrame.size.width, 219);
_tableView.frame = newTableFrame;
}];
}
}
這種方法是從方法中調用:返回最大尺寸屬性(高度或寬度)。
如果我開始肖像我可以TAPP一個表格單元格和方法的tableView視圖:didSelectRowAtIndexPath方法:被調用。旋轉到橫向模式後,所有單元格都不可選,我無法在表格中滾動。但是,如果我離開此屏幕並再次調用ison(在橫向模式下),則可以選擇相同的表格單元格,調用該方法並可以在表格中漫步。如果我將設備旋轉到縱向,我也有同樣的錯誤行爲。在我的設備旋轉後,我無法與我的桌子及其單元互動。
有人可以幫我或有一個想法是什麼,這裏是我的問題? 謝謝!
如果我這個標誌設置爲我的超級視圖_tableContainerView表不再可見。所以我認爲我的containerView有問題。現在我正在尋找原因,但我找不到任何東西。我比較了容器和表格視圖的反彈和幀,但看起來像預期的那樣。 – Thomas
你可以發佈一個包含所有這些視圖和一些虛擬數據的示例項目嗎? – Erik
好吧,我發現我的問題 - 自動調整口罩。方法將旋轉到接口方向:在設備旋轉之前執行。所以所有元素都處於正確的位置。現在,該設備旋轉,我的自動調整掩碼更改新情況的元素。不幸的是我的容器視圖非常小。感謝您的答案! – Thomas