简体   繁体   English

如果UIProgressView.progress正在移动

[英]If UIProgressView.progress is moving

I'm new to Xcode. 我是Xcode的新手。

I need a If Statement that asks IF the UIProgressView progress (float) goes bigger or smaller then do something. 我需要一个If语句,询问UIProgressView进度(浮动)是否变大或变小,然后执行一些操作。

Thanks for any help. 谢谢你的帮助。

if (myProgV is moving) {

//Do something

}

As the others have hinted, you've got this backwards. 正如其他人所暗示的,您已经倒退了。 A progress view is a view object. 进度视图是一个视图对象。 It displays things. 它显示事物。 It is not supposed to save state information. 不应保存状态信息。

You should read up on the MVC design pattern. 您应该阅读MVC设计模式。 View objects should not be used to store things. 视图对象不应用于存储事物。

I would suggest adding a property to your view controller. 我建议将一个属性添加到您的视图控制器。 Let's call it progress. 我们称之为进步。 Say it has a value that ranges from 0 to 1. 说它的取值范围是0到1。

Implement a custom setter for your progress property that sets a progress view, and also saves the value to the property's instance variable: 为您的progress属性实现一个自定义设置器,以设置进度视图,并将该值保存到该属性的实例变量中:

- (void) setProgress: (CGFloat) progress;
{
   _progress = progress;
   [myProgressView setProgress: progress animated: yes];
   //Do anything else here that you need to to respond to a change in progress.
}

Now, since you have a property, you can also query the value of progress at any point: 现在,由于有了属性,您还可以随时查询progress的值:

if (self.progreess > .5) 
  NSLog(@"More than halfway done!");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM