4
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
//Landscape mode.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //Frame for iPad
{
[deleteButton setFrame:CGRectMake(984, 7, 30, 30)];
[editButton setFrame:CGRectMake(944, 7, 30, 30)];
}
else
{
if ([[UIScreen mainScreen] bounds].size.height==568)
{
[deleteButton setFrame:CGRectMake(530, 10, 30, 30)]; //Frame for iPhone
[editButton setFrame:CGRectMake(490, 10, 30, 30)];
}
else
{
[deleteButton setFrame:CGRectMake(440, 10, 30, 30)]; //Frame for iPhone
[editButton setFrame:CGRectMake(400, 10, 30, 30)];
}
}
}
else
{
//Portrait mode.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //Frame for iPad
{
[deleteButton setFrame:CGRectMake(730, 7, 30, 30)];
[editButton setFrame:CGRectMake(690, 7, 30, 30)];
}
else
{
[deleteButton setFrame:CGRectMake(280, 7, 30, 30)]; //Frame for iPhone
[editButton setFrame:CGRectMake(240, 7, 30, 30)];
}
}
[cell.contentView addSubview:editButton]; //Added button subview to cell.
[cell.contentView addSubview:deleteButton];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell; //This code is being executed perfectly in iOS 6 also.
我正在開發一個通用應用程序。但是當我運行該應用程序時,在iOS 7中運行得非常好,在iOS 6的情況下,自定義編輯&刪除按鈕在屏幕加載時第一次出現。但是當我改變方向時,它從屏幕上消失。我正在重新加載表格視圖,同時更改方向,但仍然消失。任何人都可以幫助我。觸及項目的最後一點。iOS 6中改變方向後,UITableViewCell contentView按鈕消失
首先,我不會基於UIDeviceOrientation在這種情況下,如果您只想區分風景和肖像作爲設備的方向也可能是面向上和向下。使用UIInterfaceOrientation和(如果它是視圖控制器self.interfaceOrientation)。然後,我將不得不進行調試,看看究竟出了什麼問題,但是您以非常糟糕的方式進行了框架設置。嘗試使用自動調整掩碼,因爲我認爲你可以在你的情況下引用一些角點,一個代碼對所有情況的次要條件不是很大,如你所說的關於iOS版本的if/else –
也許你放置了代碼一個不被調用的錯誤方法。你從哪裏打電話給這個? –
我reloadData在我的表視圖在「willRotateToInterfaceOrientation:duration:」,所以每當我更改interfaceOrientation每次cellForRowAtIndexPath正在執行。我也調試過,框架的代碼正在正確執行,但不顯示。 –