2014年9月29日 星期一

XCode 6 下 Autolayout 的使用下 UICollectionViewCell 在ios8正常 但是在ios7會變形

在使用Autolayout的時候,會發生ios8顯示正常,但是執行在ios7下會出現畫面跑調的問題,那解決方法如下

此為ios8的執行結果:                                      

此為ios7的執行結果:


可以看到本來在photo的地方應該要被autolayout下他的height會變成0但是沒有。


在你customCell.m內新增加以下程式:

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    BOOL contentViewIsAutoresized = CGSizeEqualToSize(self.frame.size, self.contentView.frame.size);
    
    if( !contentViewIsAutoresized) {
        CGRect contentViewFrame = self.contentView.frame;
        contentViewFrame.size = self.frame.size;
        self.contentView.frame = contentViewFrame;
    }
}

沒有留言:

張貼留言