Giter Site home page Giter Site logo

Comments (9)

PierrePerrin avatar PierrePerrin commented on May 22, 2024

Hi I think tou forget to paste your code.
Normally the Shadow view uses its subview to prepare the shadow.
If you set a rounded subview, you shadow should be sound.
If tou are using a sinple UIView and want a circle shadowView you need to set the shadowPath to nil or override it.

from shadowview.

litt1e-p avatar litt1e-p commented on May 22, 2024
import UIKit
import SnapKit
import ShadowView

class gView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(bgView)
        bgView.addSubview(imgView)
        bgView.snp.makeConstraints { (m) in
            m.centerX.equalTo(self)
            m.centerY.equalTo(self.snp.bottom).multipliedBy(1/3.0)
            m.width.equalTo(self).multipliedBy(1/2.0)
            m.height.equalTo(bgView.snp.width)
        }
        imgView.snp.makeConstraints { (m) in
            m.edges.equalTo(bgView)
        }
        imgView.layer.cornerRadius = self.frame.size.width / 4.0
        imgView.layer.masksToBounds = true
        bgView.shadowRadius = 10
        bgView.shadowOffset = CGSize(width: 5, height: 5)
        bgView.shadowOpacity = 0.5
    }

   func assign(with img: UIImage) {
    	bgView.updateShadow()
   }

   fileprivate lazy var bgView: ShadowView = {
        let v = ShadowView(color: .clear)
        return v
    } ()
    
    fileprivate lazy var imgView: UIImageView = {
        let iv = UIImageView(contentMode: UIViewContentMode.scaleAspectFill, image: nil)
        return iv
    } ()
}

here is my code, and it crashed

I wondering that maybe updateShadow too early?

from shadowview.

PierrePerrin avatar PierrePerrin commented on May 22, 2024

Yes if you assign your image before the context is created (when the view is going to be displayed) it won't work.
I should make the context optional in order to prevent the crash.

from shadowview.

PierrePerrin avatar PierrePerrin commented on May 22, 2024

Sorry, you must set a frame to the shadow view before adding it to your view.
More than that, you never set the image of your imageView.

from shadowview.

litt1e-p avatar litt1e-p commented on May 22, 2024

I modify the func assign():

func assign(with url: URL) {
    	imgView.yy_setImage(with: url, placeholder: nil, options: [], completion: { (image, url, type, stage, error) in
            if let _ = image {
                bgView.updateShadow()
            }
        })
  }

but it still not work.

from shadowview.

PierrePerrin avatar PierrePerrin commented on May 22, 2024

Is shadow view working in the example ?
Do try to edit the example to make the effect you want ?
Without debugging I won't be able to help you with your problem...

from shadowview.

litt1e-p avatar litt1e-p commented on May 22, 2024

yes, I think the reason is the image of the imageView, it is nil when get asImage from CALayer.

and I wonder why get image from layer instead of getting image from imageView's subView. It works after I modify codes below:

from shadowview.

litt1e-p avatar litt1e-p commented on May 22, 2024

@PierrePerrin sorry about previous bug I made, I fixed it now by set bgView's frame and image. Thanks again

from shadowview.

litt1e-p avatar litt1e-p commented on May 22, 2024

And by the way, the version 1.2.1 is not found in cocoapods

from shadowview.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.