Comments (9)
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.
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.
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.
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.
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()
}
})
}
from shadowview.
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.
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.
@PierrePerrin sorry about previous bug I made, I fixed it now by set bgView's frame and image. Thanks again
from shadowview.
And by the way, the version 1.2.1
is not found in cocoapods
from shadowview.
Related Issues (5)
- Shadow generation too long HOT 2
- Render to long.
- Is it still working? HOT 2
- addSubview so lag HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shadowview.