UIView动画导致标签抽搐

时间:2016-11-13 02:42:10

标签: ios swift animation uiview uilabel

我有一个IconView课程,我将其用作Google地图标记的自定义图片。所有打印语句都显示代码正在执行。然而," 12:08" UILabel circleView adjustsFontSizeToFitWidth继续增长和缩小(即抽搐)。我无法弄清问题可能是什么。我尝试在完成功能块中手动设置字体,注释掉circleView,将UIButton更改为import UIKit class IconView: UIView { var timeLabel: UILabel! var circleView: UIView! var clicked: Bool! //constants let circleViewWidth = 50.0 let circleViewHeight = 50.0 override init(frame:CGRect) { super.init(frame : frame) self.backgroundColor = UIColor(red: 47/255, green: 49/255, blue: 53/255, alpha: 0.0) clicked = false if !clicked { //MAIN CIRCLE print("init circle view") circleView = UIView(frame: CGRect(x:0, y:0, width:circleViewWidth, height:circleViewHeight)) circleView.backgroundColor = UIColor(red: 47/255, green: 49/255, blue: 53/255, alpha: 1.0) circleView.layer.cornerRadius = circleView.frame.size.height / 2.0 circleView.layer.masksToBounds = true self.addSubview(circleView) timeLabel = UILabel(frame: CGRect(x: 0, y: 0, width: circleViewWidth, height: circleViewHeight/3.0)) timeLabel.center = circleView.center timeLabel.text = "12:08" timeLabel.textAlignment = .center timeLabel.textColor = .white timeLabel.numberOfLines = 0 timeLabel.font = UIFont.systemFont(ofSize: 11) timeLabel.font = UIFont.boldSystemFont(ofSize: 11) timeLabel.adjustsFontSizeToFitWidth = true circleView.addSubview(timeLabel) } } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } }

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
        let iconView = marker.iconView as! IconView
        print("going to start animating")
        if !iconView.clicked {
            UIView.animate(withDuration: 0.2, animations: {
                print("making this bigger now")
                iconView.circleView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
            })
            { (finished:Bool) -> Void in
                print("DONE")
                iconView.clicked = true
            }
        }
        return true
    }
{{1}}

0 个答案:

没有答案