Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Indicator is not centred like default indicator type #797

Closed
ahmed-rafiullah opened this issue Oct 23, 2017 · 2 comments
Closed

Custom Indicator is not centred like default indicator type #797

ahmed-rafiullah opened this issue Oct 23, 2017 · 2 comments

Comments

@ahmed-rafiullah
Copy link

ahmed-rafiullah commented Oct 23, 2017

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

Custom Indicator is not centred like default indicator type

What

The custom indicator UIView shows up on top left side of the corner always

Reproduce

  1. Make a custom indicator using UIView subclass
  2. Conform UIView Class to Indicator Protocol
  3. Initialise UIView using CGRect(x: 99 , y: 99, width: 30, height: 30)
  4. And set the image view indicator to .custom(indicator: bounceLoader)

Here is the relevant code

BounceLoader.swift
import UIKit
import Kingfisher

class BounceLoader: UIView {
    
    var outerCirlce: UIView = UIView()
    var innerCircle: UIView = UIView()
    
    
    let transformOne = CGAffineTransform(scaleX: 0.01, y: 0.01)
    let transformTwo = CGAffineTransform(scaleX: 1.6, y: 1.6)
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }
    
    
    func commonInit() {
        
        self.backgroundColor = UIColor.clear
        
        outerCirlce.frame = bounds
        innerCircle.frame = bounds
        
        
        
        
        
        makeUIViewCircle(view: outerCirlce)
        makeUIViewCircle(view: innerCircle)
        
        makeUIViewTranslucent(view: outerCirlce, blurStyle: .dark)
        makeUIViewTranslucent(view: innerCircle, blurStyle: .light)
        
        addSubview(outerCirlce)
        addSubview(innerCircle)
        
        startAnimation()
    }
    
    
    
    private func makeUIViewCircle(view: UIView) {
        view.layer.cornerRadius = view.frame.width/2
    }
    
    
    private func makeUIViewTranslucent(view: UIView, blurStyle: UIBlurEffectStyle) {
        view.backgroundColor = UIColor.clear
        let blurEffect = UIBlurEffect(style: blurStyle)
        let uiVisualEffect = UIVisualEffectView(effect: blurEffect)
        uiVisualEffect.frame = view.bounds
        uiVisualEffect.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.clipsToBounds = true
        view.addSubview(uiVisualEffect)
    }
    
    
    func startAnimation() {
        self.isHidden = false
        UIView.animate(withDuration: 0.6, delay: 0.0, options: [.autoreverse,.repeat,.curveEaseOut,.beginFromCurrentState,.preferredFramesPerSecond60], animations: { [weak self] in
            
            guard let `self` = self else {
                return
            }
            
            self.innerCircle.transform = self.transformOne
            self.outerCirlce.transform = self.transformTwo
            
            
            }, completion: nil)
    }
    
    
    func stopAnimation(){
        self.isHidden = true
        
    }
    
    
    
}

MyIndicator.swift
struct MyIndicator: Indicator {
    
    let loader = BounceLoader(frame: CGRect(x: 0.0, y: 0.0, width: 30.0, height: 30.0))
    var view: IndicatorView {
        return loader
    }
    
    func startAnimatingView() { loader.startAnimation()() }
    func stopAnimatingView() { loader.stopAnimation() }
    
}

ViewController.swift

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: photoViewCellIdentifier, for: indexPath) as! PhotoCollectionViewCell
            
let url = URL(string: photo.urls.regular)
cell.photoImageView.backgroundColor = UIColor.hexStringToUIColor(hex: photo.color)
            
cell.photoImageView.kf.indicatorType = .custom(indicator: MyIndicator())
            
cell.photoImageView.kf.setImage(with: url , options: [.transition(.fade(0.4))])
            
return cell

@onevcat
Copy link
Owner

onevcat commented Oct 24, 2017

I think I found an issue in setting indicator frame. I pushed a fix on it. could you try whether it could work for you? See here: #798

@Reelevant
Copy link

This issue is not solved in current version 4.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants