如何自动圆化弹出视图的边缘?
How can I automatically round the edges of a popup view?
我正在为我正在制作的应用程序制作弹出视图。如果您花点时间看一下下面的图片,您会发现顶部边缘是圆形的,但底部边缘不是。这是因为我只圆化了视图的边缘(它在层次结构中处于最低位置)。我无法将图像的边缘(彩色框)四舍五入,因为它们是滚动视图中的表格。我能想到的唯一解决方案是一个非常丑陋的解决方案,我用一个 UIImageView 掩盖底部边缘,一旦弹出窗口消失,它就会出现。有没有人有更好的解决方案?如果是这样,我将非常感谢您的帮助。另外,我的滚动视图还没有功能,所以这里没有引用它,解决方案(如果功能)应该无论如何都可以工作。
我的代码:
allSeenPopover.layer.cornerRadius = 5
userProfile.layer.cornerRadius = 15
colorBackground.layer.cornerRadius = 15
colorBackground.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
@IBAction func loadUserProfile(_ sender: Any) {
if darken.alpha == 0 {
darken.alpha = 1
self.view.addSubview(userProfile)
userProfile.center = self.view.center
userProfile.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
userProfile.alpha = 0
UIView.animate(withDuration: 0.3) {
self.largeDropShadow.alpha = 0.3
self.userProfile.alpha = 1
self.userProfile.transform = CGAffineTransform.identity
}
}
else {
UIView.animate(withDuration: 0.2, animations: {
self.userProfile.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
self.userProfile.alpha = 0
self.darken.alpha = 0
self.largeDropShadow.alpha = 0
}) { (success:Bool) in
self.userProfile.removeFromSuperview()
}
}
}
我指的是图片:
由于您想要舍入的视图位于 table 视图单元格内,因此您必须注意视图在创建时只在每个重用单元格中添加一次。
每次重复使用的单元格滚动到视图中时,检查它是否有 imageView 子视图(使用单元格中唯一的标签 是一种快速制作的方法那个支票)。如果没有,请创建它,然后为特定行配置它,否则只需为特定行配置它...
(警告,我不swift流利,但思路应该很清楚)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as UITableViewCell!
let imageView:UIImageView = cell.viewWithTag(99) as? UIImageView
if (!imageView) {
// this code runs just once per reused cell, so setup
// imageView properties here that are row-independent
imageView = UIImageView()
imageView.tag = 99 // so we'll find this when the cell gets reused
imageView.layer.cornerRadius = 15.0
imageView.clipsToBounds = true
// any other props that are the same for all rows
imageView.frame = // your framing code here
cell.addSubview(imageView)
}
// this code runs each time a row scrolls into view
// so setup properties here that are row-dependent
imageView.image = // some function of indexPath.row
return cell
}
我正在为我正在制作的应用程序制作弹出视图。如果您花点时间看一下下面的图片,您会发现顶部边缘是圆形的,但底部边缘不是。这是因为我只圆化了视图的边缘(它在层次结构中处于最低位置)。我无法将图像的边缘(彩色框)四舍五入,因为它们是滚动视图中的表格。我能想到的唯一解决方案是一个非常丑陋的解决方案,我用一个 UIImageView 掩盖底部边缘,一旦弹出窗口消失,它就会出现。有没有人有更好的解决方案?如果是这样,我将非常感谢您的帮助。另外,我的滚动视图还没有功能,所以这里没有引用它,解决方案(如果功能)应该无论如何都可以工作。
我的代码:
allSeenPopover.layer.cornerRadius = 5
userProfile.layer.cornerRadius = 15
colorBackground.layer.cornerRadius = 15
colorBackground.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
@IBAction func loadUserProfile(_ sender: Any) {
if darken.alpha == 0 {
darken.alpha = 1
self.view.addSubview(userProfile)
userProfile.center = self.view.center
userProfile.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
userProfile.alpha = 0
UIView.animate(withDuration: 0.3) {
self.largeDropShadow.alpha = 0.3
self.userProfile.alpha = 1
self.userProfile.transform = CGAffineTransform.identity
}
}
else {
UIView.animate(withDuration: 0.2, animations: {
self.userProfile.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
self.userProfile.alpha = 0
self.darken.alpha = 0
self.largeDropShadow.alpha = 0
}) { (success:Bool) in
self.userProfile.removeFromSuperview()
}
}
}
我指的是图片:
由于您想要舍入的视图位于 table 视图单元格内,因此您必须注意视图在创建时只在每个重用单元格中添加一次。
每次重复使用的单元格滚动到视图中时,检查它是否有 imageView 子视图(使用单元格中唯一的标签 是一种快速制作的方法那个支票)。如果没有,请创建它,然后为特定行配置它,否则只需为特定行配置它...
(警告,我不swift流利,但思路应该很清楚)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as UITableViewCell!
let imageView:UIImageView = cell.viewWithTag(99) as? UIImageView
if (!imageView) {
// this code runs just once per reused cell, so setup
// imageView properties here that are row-independent
imageView = UIImageView()
imageView.tag = 99 // so we'll find this when the cell gets reused
imageView.layer.cornerRadius = 15.0
imageView.clipsToBounds = true
// any other props that are the same for all rows
imageView.frame = // your framing code here
cell.addSubview(imageView)
}
// this code runs each time a row scrolls into view
// so setup properties here that are row-dependent
imageView.image = // some function of indexPath.row
return cell
}