标签更改(xcode)(swift)时将调用viewDidLayoutSubviews [英] viewDidLayoutSubviews is called when label changes (xcode) (swift)

查看:148
本文介绍了标签更改(xcode)(swift)时将调用viewDidLayoutSubviews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有一个标签,切换按钮和一个动画.当我按下切换按钮->动画开始时,标签会更改.下面是我的代码示例.

I have a label, toggle button and an animation in my code. When I press the toggle button -> animation starts , label changes. Below is my code sample.

override func viewDidLayoutSubviews() {
println("viewDidLayoutSubviews is called")
// Initial state of my animation.
     }

 @IBAction func Toggled(sender: AnyObject) {
    CallTextChange() 
   // Two different Animations        
     }

 func CallTextChange() { // Change text here}

每次我更改标签viewDidLayoutSubviews中的文本时,都会调用一次. 每次更改标签时,有没有办法停止调用它?

Every time I change the text in label viewDidLayoutSubviews is called. Is there a way to stop calling it every time I change the label?

推荐答案

我找到了解决问题的答案.

I found the answer for my problem.

当我们从Xcode提供的对象中拖放创建UIImage时,图像被临时放置在静态放置的位置.因此,当调用viewDidLayoutSubviews进行中间动画时,图像将放置在静态位置. 因此,必须以编程方式创建UIImage.

When we create UIImage by drag and dropping from the object provided by Xcode, the image is temporary placed where it was statically placed. So when animating in middle when viewDidLayoutSubviews is called the image is placed in the static place. So the UIImage has to be created programmatically.

CreateImage.image = UIImage(named: "Image.png")
CreateImage = UIImageView(frame: CGRect(x: 0, y: 0, width: CreateImage.image!.size.width/6, height: CreateImage.image!.size.height/6))
self.view.addSubview(CreateImage)

这篇关于标签更改(xcode)(swift)时将调用viewDidLayoutSubviews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆