【问题标题】:UITableView rotation behaving strange after Xcode 6 and iOS 8 updateXcode 6 和 iOS 8 更新后 UITableView 旋转表现奇怪
【发布时间】:2014-10-02 00:30:34
【问题描述】:

我一直在开发一个应用程序,它进展顺利。然而,这个周末我更新到 Xcode 6,现在我的应用程序的行为与更新到 Xcode 6 之前不同。

我的应用中有一个 UITableView,我在 viewDidLoad 中旋转:

//Rotate playerCardsTable.
CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
_playerCardsTable.transform = rotateTable;
_playerCardsTable.frame = CGRectMake(0, 0, _playerCardsTable.frame.size.width, _playerCardsTable.frame.size.height);

在更新之前的 Xcode(Xcode 5)中,我有这样的看法:

但是现在,在更新到 Xcode 6 之后,我有了这样的看法:

tableview 是旋转的,所以我有水平滚动,但看起来框架在旋转后没有正确更改。它高 320 像素,宽 80 像素,应该是相反的。我不知道为什么,但我似乎无法在代码中更改框架,换句话说,我在更改宽度和高度后看不到任何变化。

tableview 是通过界面构建​​器添加的,并包含自定义单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{ 静态 NSString *CellIdentifier = @"Cell";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

NSString *cardName = [[[[[Game game] localPlayer] playerCards] objectAtIndex:indexPath.row] fileNameCard];
cell.cardImage.image = [UIImage imageNamed:cardName];

Card *card;
card = [[[[Game game] localPlayer] playerCards] objectAtIndex:indexPath.row];

if(card.playable == IsPlayable){
    cell.backgroundColor = isPlayableColor;}
else if (card.playable == IsNotPlayable) {
    cell.backgroundColor = isNotPlayableColor;}
else if (card.playable == IsReallyPlayable) {
    cell.backgroundColor = isReallyPlayableColor;}


//Rotate image to align with rotated tableview.
CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI/2);
cell.cardImage.transform = rotateImage;
cell.playableImage.transform = rotateImage;

cell.cardImage.layer.borderWidth = 2;
cell.cardImage.layer.borderColor = [UIColor clearColor].CGColor;
cell.cardImage.layer.shouldRasterize = YES;
cell.cardImage.layer.rasterizationScale = [[UIScreen mainScreen] scale];

cell.cardImage.layer.shadowColor = [UIColor blackColor].CGColor;
cell.cardImage.layer.shadowOffset = CGSizeMake(0, 1);
cell.cardImage.layer.shadowOpacity = 0.7;
cell.cardImage.layer.shadowRadius = 2.0;
cell.cardImage.clipsToBounds = NO;

return cell;}

要清楚;更新后我没有更改任何代码,因此不同的行为是由更新引起的。

希望你们能帮忙。

谢谢!

【问题讨论】:

    标签: ios xcode uitableview


    【解决方案1】:

    我最近在将 iPad 升级到 ios8 后遇到了非常相似的情况 - 水平表格显示不正确。

    我没有完整的解决方案,但可以通过研究和测试告诉您,在我的情况下,这是由于转换操作和 UITableView 上的 AutoLayout 约束不协调/合作。显然,这两个概念协同工作的方式在 ios8 中发生了一些变化。

    情节提要中设置的 top 约束在转换后变为 left 约束(或右,从未正确计算出来)。

    对我来说,最重要的是,在尝试了多种约束组合之后,包括在转换之前删除它们,然后在转换之后重新添加约束,我最终从 UITableView 转换为 UICollectionView

    【讨论】:

    • 我没有得到任何回复,所以我只是添加了一个新的UITableView 并从那里开始工作。我认为你对AutoLayout 的想法是正确的,但我就是无法修复它。所以我从UITableView 重新开始并添加了新的约束等。现在它按预期工作。还是谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 2012-09-13
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多