我必须每次< strong>重操作1秒。我正在使用NSTimer,但它并不像我预期的那样准确......我正在使用2个定时器。一个用于更新模型中的数据,另一个用于更新我的视图(少量标签和自定义'花式圈'进度条)
好的......我的代码:
_valueTimer =
[NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(counterTask)
userInfo:nil
repeats:YES];
_progressTimer =
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(updateViews) // heavy stuff here
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_progressTimer
forMode:NSRunLoopCommonModes];
正如您所见,_progressTimer
选择器每0.1秒运行一次。
其中一个观点是我的HH:MM:SS时间(来自第一个计时器的数据!)。我的进度条更新时显示的时间与实时不同(繁重操作) - >应用程序10秒= 12秒实时...它有太大的区别。当我评论我的进度条更新时 - 一切正常
你能告诉我如何强制我的计时器在我的间隔后完全运行吗?或者当它太多而无法处理时跳过一个循环?最重要的是不要放慢脚步......
由于
答案 0 :(得分:0)
您可以尝试使用<?php
$gmail_username = 'username@gmail.com';
$gmail_password = 'password';
$to = "contact@ihabovich.ga";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = "[Contact form] You have a message from $name.";
$fields = array();
$fields{"name"} = "Name";
$fields{"email"} = "Email";
$fields{"phone"} = "Phone";
$fields{"department"} = "Department";
$fields{"message"} = "Message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername($gmail_username)
->setPassword($gmail_password)
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance($subject)
->setFrom($gmail_username)
->setReplyTo(array($from => $name))
->setTo($to)
->setBody($body);
// Send the message
$result = $mailer->send($message);
?>
计时器将动画/绘图与设备显示的刷新率同步(即iOS设备每秒60次)。
CADisplayLink
因为您的方法(此处self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLinkTimerFired:)];
//_displayLink.frameInterval = 3; // slows the updates for debugging
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
:)会经常被调用,所以您不想进行繁重的处理,否则您可能会丢失帧。
答案 1 :(得分:0)
确定。我找到了解决方案也许并不完美,但它确实有效。
在var days = ["Mon", [true, false]]
let json = NSJSONSerialization.dataWithJSONObject(days, options: NSJSONWritingOptions.PrettyPrinted, error: nil)
let _days = NSJSONSerialization.JSONObjectWithData(json!, options: NSJSONReadingOptions.allZeros, error: nil) as! Array<AnyObject>
println(_days[0]) // prints Mon
println(_days[1][0]) // prints 1
方法中,不是将我的counterTask
值增加0.01 ...我计算了&#39; ticks&#39;之间的实际间隔。像这样:
_actualTime