2016-05-23 16 views
0

渲染圖像視圖中的所有邊角角半徑這是它的外觀前:如何設置與UIGraphicsGetImageFromCurrentImageContext

enter image description here

後,我產生拖觀點:

enter image description here

和這是我如何生成單元格的拖動視圖:

private func setupDraggingViewForCell(cell: BWStudentWishlistBookCollectionViewCell) { 

    UIGraphicsBeginImageContextWithOptions(cell.bounds.size, false, 0) 
    cell.bookImageView.layer.renderInContext(UIGraphicsGetCurrentContext()!) 

    draggingView = UIImageView(image: UIGraphicsGetImageFromCurrentImageContext()) 
    draggingView?.clipsToBounds = true 
    draggingView?.contentMode = .ScaleAspectFit 
    draggingView?.layer.masksToBounds = true 
    draggingView?.layer.cornerRadius = 10 

    view.addSubview(draggingView!) 

    UIGraphicsEndImageContext() 
} 

正如您所看到的,只有一個圓角是圓角的。爲什麼?

+1

我認爲你的拖動視圖小於圖像..你有剪輯綁定=是可能 –

+0

我認爲你必須設置draggingView的框架(尤其是起源) –

回答

-1

不知道,但嘗試圓形圖像比ImageView的

func makeRoundedImage(image: UIImage, radius: Float) -> UIImage { 
    var imageLayer: CALayer = CALayer.layer 
    imageLayer.frame = CGRectMake(0, 0, image.size.width, image.size.height) 
    imageLayer.contents = (image.CGImage as! AnyObject) 
    imageLayer.masksToBounds = true 
    imageLayer.cornerRadius = 10 
    UIGraphicsBeginImageContext(image.size) 
    imageLayer.renderInContext(UIGraphicsGetCurrentContext()) 
    var roundedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 
    return roundedImage 
} 

,然後設置圖像您圖像視圖。並清除dragableView的背景顏色

希望它會幫助..!

0

您可以將clipsToBounds設置爲false,並且可能會解決您的問題。否則,它會向您顯示封面的全部框架,然後您可以決定做什麼。

draggingView?.clipsToBounds = false 
0

您可以直接否則這段代碼添加到您的自定義單元格根據自己的需要.......

override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
     imageView.layer.shadowColor = UIColor.blackColor().CGColor 
     imageView.layer.shadowOpacity = 1 
     imageView.layer.cornerRadius = 5 
     imageView.layer.shadowOffset = CGSizeZero 
     imageView.layer.shadowRadius = 2 

//If you added Aspect to Fill 
     imageView.clipsToBounds = true 
    } 

我希望這將幫助你...(Y)

相關問題