Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问现在高度能自适应吗? #48

Open
jxbaoweiyj opened this issue Jan 15, 2018 · 3 comments
Open

请问现在高度能自适应吗? #48

jxbaoweiyj opened this issue Jan 15, 2018 · 3 comments

Comments

@jxbaoweiyj
Copy link

现在好像都在

  • (CGFloat)heightByModel:(TangramDefaultItemModel *)itemModel;
    {
    return 100.f;
    }
    这里面写死高度?
@HarrisonXi
Copy link
Contributor

额,不要慌,这是我在 demo 里偷懒了……

这里就是计算高度的 protocol 方法,在这里返回根据模型计算得到的高度即可,Tangram 会通过这个借口取高度。

@jxbaoweiyj
Copy link
Author

弱弱的问下,在(CGFloat)heightByModel:(TangramDefaultItemModel *)itemModel;
{
return 100.f;
}
这里面怎么根据模型算高度?如果我想直接根据imageview的image的高度来计算,这里面怎么写?类方法里不是不能用实例变量吗?

@HarrisonXi
Copy link
Contributor

如果要根据image的高度来动态计算,的确会比较难受。

阿里CDN的图片地址都是带宽高比的,例如 https://img.alicdn.com/tfs/TB1JIM.klfH8KJjy1XbXXbLdXXa-167-70.jpg ,我们就可以根据 URL 里的宽高比来计算。

如果你们的图片是宽高比不固定,URL 还不带尺寸,建议方案:

  1. 服务端下发图片的时候用模型下发,带上宽高比。

即 {imgUrl : "xxx"} => {img : {url : "xxx", width : 100, height : 100}}

  1. 预加载图片获得宽高比。

  2. 固定图片宽高比。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants