IOS:使用CGAffineTransform调整视图大小

时间:2017-03-23 21:11:25

标签: ios cgaffinetransform

我无法进行CGAffineTransform转换以扩展表格单元格中的视图而无法理解原因。

任何人都可以看到有什么问题。这是我的代码:

UIView* resizedView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
        [resizedView addSubview:view];
        [cell addSubview:view];

        CGSize sizeDifference = CGSizeMake(resizedView.frame.size.width - view.frame.size.width, view.frame.size.height - view.frame.size.height);
            NSLog(@"width = %f, height = %f", sizeDifference.width, sizeDifference.height);

        CGSize transformRatio = CGSizeMake(resizedView.frame.size.width / view.frame.size.width, view.frame.size.height / view.frame.size.height);

        //  Original transform
        CGAffineTransform transform = CGAffineTransformIdentity;

        //  Scale custom view so image will fill entire cell
        transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height);

        //  Move custom view so the old vie's top left aligns with the cell's top left
        transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2.0, -sizeDifference.height / 2.0);

        [resizedView setTransform:transform];

视图保持完全相同。非常感谢任何建议。

0 个答案:

没有答案