由于SDAutoLayout是采用的延迟布局,采用transform旋转45度可能看不到旋转的图片(旋转90度可以看到)。解决方案对图片使用frame,不采用SDAutoLayout布局。
有问题的代码:
- (UIImageView *)photoImageView { if(!_photoImageView) { _photoImageView = [self createImageView]; _photoImageView.backgroundColor = [UIColor clearColor]; // _photoImageView.image = nil; // _photoImageView.hidden = NO; // _photoImageView.layer.cornerRadius = COMMON_CORNER_RADIUS; [_photoImageView.layer setMasksToBounds:YES]; _photoImageView.contentMode = UIViewContentModeScaleAspectFill;//等比缩放图片把整个ImageView填充满,所以可能会出现图片部分显示不出来 UIViewContentModeScaleAspectFit;//等比缩放把图片整体显示在ImageView中,所以可能会出现ImageView有空白部分 // [_photoImageView sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590415038677&di=82015f4c7e78320f539b5b350cbef411&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F0e2442a7d933c895f7116ee6d01373f08202003b.jpg"]]; // [_photoImageView addCornerWithCornerRadius:80.0]; // _photoImageView.frame = CGRectMake((475 - 357)/2, (FULL_HEIGHT-kNavBarAndStatusBarHeight- 357 -65 - 36 - 20 -24)/2, 357, 357); _photoImageView.transform = CGAffineTransformMakeRotation(M_PI_4); // _photoImageView.center = self.center; // _photoImageView.transform = CGAffineTransformMakeRotation(M_PI/4); // CGAffineTransform transform= CGAffineTransformMakeRotation(0.785398); // _photoImageView.transform = transform;//旋转 } return _photoImageView; }
self.photoImageView.sd_layout .leftSpaceToView(self.describeTitleBackground, (475 - 357)/2) .topSpaceToView(self.describeTitleBackground, (FULL_HEIGHT-kNavBarAndStatusBarHeight- 357 -65 - 36 - 20 -24)/2) .widthIs(357) .heightIs(357);
正确的代码:
- (UIImageView *)photoImageView { if(!_photoImageView) { _photoImageView = [self createImageView]; _photoImageView.backgroundColor = [UIColor clearColor]; // _photoImageView.image = nil; // _photoImageView.hidden = NO; // _photoImageView.layer.cornerRadius = COMMON_CORNER_RADIUS; [_photoImageView.layer setMasksToBounds:YES]; _photoImageView.contentMode = UIViewContentModeScaleAspectFill;//等比缩放图片把整个ImageView填充满,所以可能会出现图片部分显示不出来 UIViewContentModeScaleAspectFit;//等比缩放把图片整体显示在ImageView中,所以可能会出现ImageView有空白部分 // [_photoImageView sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590415038677&di=82015f4c7e78320f539b5b350cbef411&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F0e2442a7d933c895f7116ee6d01373f08202003b.jpg"]]; // [_photoImageView addCornerWithCornerRadius:80.0]; _photoImageView.frame = CGRectMake((475 - 357)/2, (FULL_HEIGHT-kNavBarAndStatusBarHeight- 357 -65 - 36 - 20 -24)/2, 357, 357); _photoImageView.transform = CGAffineTransformMakeRotation(M_PI_4); // _photoImageView.center = self.center; // _photoImageView.transform = CGAffineTransformMakeRotation(M_PI/4); // CGAffineTransform transform= CGAffineTransformMakeRotation(0.785398); // _photoImageView.transform = transform;//旋转 } return _photoImageView; }
self.photoImageView.sd_layout // .leftSpaceToView(self.describeTitleBackground, (475 - 357)/2) // .topSpaceToView(self.describeTitleBackground, (FULL_HEIGHT-kNavBarAndStatusBarHeight- 357 -65 - 36 - 20 -24)/2) // .widthIs(357) // .heightIs(357);