我有一个自定义的UICollectionView布局,当用户滚动时会调整大小.当标题在某一点缩小时,它开始闪烁.
我猜测问题是,当标题收缩时,集合视图认为它不在帧中并且可能使其出列但是它会计算出它在帧中并重新排队,这可能是导致闪烁的原因.
class CustomLayout: UICollectionViewFlowLayout, UICollectionViewDelegateFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let layoutAttributes = super.layoutAttributesForElements(in: rect) as! [UICollectionViewLayoutAttributes]
let offset = collectionView!.contentOffset ?? CGPoint.zero
let minY = -sectionInset.top
if (offset.y >= minY) {
let setOffset = fabs(170 - minY)
let extraOffset = fabs(offset.y - minY)
if offset.y <= 170 {
for attributes in layoutAttributes {
if let elementKind = attributes.representedElementKind {
if elementKind == UICollectionElementKindSectionHeader {
var frame = attributes.frame
frame.size.height = max(minY, headerReferenceSize.height - (extraOffset …
Run Code Online (Sandbox Code Playgroud) 使用语法有点困惑.我知道你应该使用NSFontAttributeName,但我不知道如何正确指定范围.
我很好奇两个案例.
如何指定文本中所有字符的范围,以及如何将范围指定为前10个字符.
有什么建议?
以下是我的纵断面图约束,该视图渲染效果很好,但是宽度始终返回零。因此,最终约束profileImageView.layer.cornerRadius =(profile.frame.width / 2)每次都返回零。
profileImageView.translatesAutoresizingMaskIntoConstraints = false
addConstraint(NSLayoutConstraint(item: profileImageView, attribute: .width, relatedBy: .equal, toItem: containerView, attribute: .width, multiplier: 0.125, constant: 0))
addConstraint(NSLayoutConstraint(item: profileImageView, attribute: .height, relatedBy: .equal, toItem: containerView, attribute: .width, multiplier: 0.125, constant: 0))
addConstraint(NSLayoutConstraint(item: profileImageView, attribute: .centerY, relatedBy: .equal, toItem: containerView, attribute: .centerY, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: profileImageView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 0.25, constant: 0))
profileImageView.layer.cornerRadius = (profileImageView.frame.width / 2)
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
因为UICollectionViews
,有多种细胞类型可能吗?
例如:
media_cell
regular_cell
ad_cell
Run Code Online (Sandbox Code Playgroud)
您是否只需要注册它们,或者您是否必须包含if语句并根据某个变量更改布局以实现此效果.
例如:
if cell.ad == true {
}
Run Code Online (Sandbox Code Playgroud)
原因是,我想要一个略有不同大小的单元格来存在图像.我想重新调整单元格可以工作,但我没有在网上看到任何东西.
有什么建议
我见过许多版本的彩色渐变图像,它们既是非线性的又是高度风格化的。通常呈分层斑点状形状的形式。
我对他们如何实现这种效果的猜测是
然而,正如您通过图像中的清晰线条注意到的那样,插值效果仅出现在图像的某些区域。这种效果就是我想在金属中达到的效果。
我正在开发一个使用 Twillios Programmable Video API 的应用程序。
我是使用 Node JS 的新手,但文档相当简单,但我仍然有一些问题。
这是我引用的代码。
const AccessToken = require('twilio').jwt.AccessToken;
const VideoGrant = AccessToken.VideoGrant;
// Used when generating any kind of tokens
const twilioAccountSid = 'ACxxxxxxxxxx';
const twilioApiKey = 'SKxxxxxxxxxx';
const twilioApiSecret = 'xxxxxxxxxxxx';
const identity = 'user';
// Create Video Grant
const videoGrant = new VideoGrant({
room: 'cool room'
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = …
Run Code Online (Sandbox Code Playgroud) 我有一个自定义 UICollectionViewLayout 滚动时调整标题高度的大小。
在标题内,我有一个 UIImageView,它被限制为单元格的高度。
我希望图像是圆形的,所以我相应地设置了角半径,但是当单元格调整大小时它会出现。约束成立,但拐角半径不更新。
let cellImage: UIImageView = {
let s = UIImageView()
s.clipsToBounds = true
s.contentMode = .scaleAspectFill
s.image = UIImage(named: "img")
s.translatesAutoresizingMaskIntoConstraints = false
return s
}()
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(cellImage)
cellImage.widthAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.75, constant: 0).isActive = true
cellImage.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.75, constant: 0).isActive = true
cellImage.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
cellImage.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
}
override var frame: CGRect {
didSet …
Run Code Online (Sandbox Code Playgroud) 我如何根据它的字体大小和标签文本中的字符数来预测UILabel所需的宽度.
我已经看到了一些这样做的例子,但它们都是客观的 - 不是swift 3.0.
我找到了这个方法,但它是在objective-c中,我在实现它时遇到了麻烦.
CGFloat width = [label.text sizeWithFont:[UIFont systemFontOfSize:17.0f]].width;
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我正在尝试从我的firebase数据库下载图像并将它们加载到collectionviewcells中.图像下载,但我无法让它们全部下载和异步加载.
目前,当我运行我的代码时,下载的最后一个图像加载 但是,如果我更新我的数据库,集合视图会更新,并且新的最后一个用户配置文件图像也会加载,但其余部分都会丢失.
我宁愿不使用第三方库,所以任何资源或建议将不胜感激.
这是处理下载的代码:
func loadImageUsingCacheWithUrlString(_ urlString: String) {
self.image = nil
// checks cache
if let cachedImage = imageCache.object(forKey: urlString as NSString) as? UIImage {
self.image = cachedImage
return
}
//download
let url = URL(string: urlString)
URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
//error handling
if let error = error {
print(error)
return
}
DispatchQueue.main.async(execute: {
if let downloadedImage = UIImage(data: data!) {
imageCache.setObject(downloadedImage, forKey: urlString as NSString)
self.image = downloadedImage
}
})
}).resume()
} …
Run Code Online (Sandbox Code Playgroud) swift ×8
ios ×5
xcode ×3
javascript ×1
metal ×1
node.js ×1
nsurl ×1
objective-c ×1
twilio ×1
twilio-api ×1
uiimageview ×1
uilabel ×1