Ios 如何降低左右图像的不透明度?
如何降低左右图像的不透明度?我正在使用CollectionView显示图像中的所有数据。我想降低中心左右两侧视图的不透明度。我不知道怎么做。我可以在ViewDidLayoutSubView中执行所有操作。请解决这个问题。这是我的代码:Ios 如何降低左右图像的不透明度?,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,如何降低左右图像的不透明度?我正在使用CollectionView显示图像中的所有数据。我想降低中心左右两侧视图的不透明度。我不知道怎么做。我可以在ViewDidLayoutSubView中执行所有操作。请解决这个问题。这是我的代码: var arrHeading = ["Total Visitors in last 30 Days", "Total Departments", "Total Employees"] func collectionView(_ collectionView: U
var arrHeading = ["Total Visitors in last 30 Days", "Total Departments", "Total Employees"]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return arrHeading.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VisitorDashboardCell", for: indexPath) as! VisitorDashboardCell
cell.imgBG.layer.cornerRadius = 10
cell.imgBG.layer.masksToBounds = true
//Set Gradient Color to CollectionViewCell
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.layer.shadowRadius = 2.0;
cell.layer.shadowOpacity = 0.9;
cell.layer.cornerRadius = 10
cell.layer.masksToBounds = false
cell.imgBG.layer.shadowPath = UIBezierPath(rect: CGRect(x: -8, y: -18, width: cell.frame.size.width + 8 , height: cell.frame.size.height + 18)).cgPath
cell.layoutIfNeeded()
cell.imgBG.image = UIImage.init(named: arrImage[indexPath.row])
cell.imgIcon.image = UIImage.init(named: arrIcon[indexPath.row])
cell.lblHeading.text = arrHeading[indexPath.row]
cell.lblNum.text = arrNum[indexPath.row]
return cell
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let middleValue = round(Double(arrHeading.count / 2))
print("Middle Value \(middleValue)")
if arrHeading.count < Int(middleValue)
{
var leftArray = [Int]()
for i in 0..<(Int(middleValue) - 1) {
leftArray.append(i)
}
print("Left Array \(leftArray)")
}
else if arrHeading.count > Int(middleValue)
{
var rightArray = [Int]()
for i in Int(middleValue)..<arrHeading.count
{
rightArray.append(i)
}
print("Right Array \(rightArray)")
}
else
{
//Show middle element of the collection view
let selectedIndex = IndexPath(item: Int(middleValue), section: 0)
self.collectionView.scrollToItem(at: selectedIndex, at: .centeredHorizontally, animated: false)
}
}
在您的学员身上尝试以下操作:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
UIView.animate(withDuration: 0.5) {
cell.alpha = cell.isSelected ? 1 : 0.5
}
}
我会在您选择中间元素的位置更改元素alpha。我不会在viewDidLayoutSubviews中执行所有这些代码。我要做的是实现didScroll委托,然后相应地更改alpha。滚动后,您能告诉我在可见单元格数组中显示了什么吗?didSelectItemAt函数在选定单元格时启动,而不是在collectionView中居中时启动。他可以在居中时执行类似的操作。