为什么我的CGAffineTransformMakeTranslation在iOS 7上不起作用?

Leo*_*nte 2 objective-c

在iOS 8上,上面的代码工作正常,但在iOS 7上没有,有人知道如何修复它吗?

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    // headerFixed is an UIView inside of a headerView, i wanna it to be fixed on Y:0
    headerFixed.transform = CGAffineTransformMakeTranslation(0, MIN(scrollView.contentOffset.y, 0)); 
}
Run Code Online (Sandbox Code Playgroud)

在iOS 8上:https: //www.youtube.com/watch?v = -428J20xbzM&feature = youtu

在iOS 7(BUG):https://www.youtube.com/watch?v = Dd_jh0zs1f0 & feature = youtu.be

Nik*_*sov 7

如果您使用iOS 8 SDK构建项目,那么在iOS 7上,您必须手动将点转换为视网膜设备上的像素;

考虑写这样的东西:

CGFloat dY = MIN(scrollView.contentOffset.y, 0);
if ([UIDevice currentDevice].systemVersion.floatValue < 8) {
   dY *= [UIScreen mainScreen].scale;
}
headerFixed.transform = CGAffineTransformMakeTranslation(0, dY); 
Run Code Online (Sandbox Code Playgroud)

虽然关闭自动布局将足以解决您的问题.