iphone - 用 Time Profiler 分析的审查方法
<p><p>我已使用 Time Profiler Instrument 来识别我的应用程序中的显着滞后。现在我知道问题出在哪里,但我不知道该怎么办。我正在使用 ARC 并有一个 viewController 调用方法“Go”,如下所示。我还包含了 Time Profiler 结果的快照。有谁知道我该如何解决这个问题?谢谢!</p>
<p><strong>这是方法的代码:</strong></p>
<pre><code>- (void)go {
CGFloat width = self.imageViewA.bounds.size.width;
[UIView animateWithDuration:18.0 delay:0.0 options:UIViewAnimationOptionCurveLinear
animations:^ {
self.imageViewA.frame = CGRectOffset(self.imageViewA.frame, -width, 0);
self.imageViewB.frame = CGRectOffset(self.imageViewB.frame, -width, 0);
}
completion:^(BOOL finished) {
if (self.keepGoing) {
// now B is where A began, so swap them and reposition B
UIImageView *temp = self.imageViewA;
self.imageViewA= self.imageViewB;
self.imageViewB = temp;
self.imageViewB.frame = CGRectOffset(self.view.bounds,
self.view.bounds.size.width, 0.0);
// recursive call, but we don't want to wind up the stack
;
}
}];
}
</code></pre>
<p><strong>这是我的时间文件的结果:</strong></p>
<p> <img src="/image/JAoUm.png" alt="enter image description here"/> </p>
<p><strong>作为引用,我还包含了我的 .h 文件。</strong></p>
<pre><code>@interface ViewController : GAITrackedViewController
@property (weak, nonatomic) IBOutlet UIBarButtonItem *lButton;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *rButton;
@property (nonatomic, assign) BOOL keepGoing;
@property (nonatomic, strong) UIImageView *imageViewA;
@property (nonatomic, strong) UIImageView *imageViewB;
- (IBAction)handleLPressed:(id)sender;
- (IBAction)handleRPressed:(id)sender;
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>也许这可以工作:</p>
<pre><code>- (void)go {
CGFloat width = self.imageViewA.bounds.size.width;
__weak typeof(self) self_ = self;
[UIView animateWithDuration:18.0 delay:0.0 options:UIViewAnimationOptionCurveLinear
animations:^ {
__strong typeof(self) self = self_;
self.imageViewA.frame = CGRectOffset(self.imageViewA.frame, -width, 0);
self.imageViewB.frame = CGRectOffset(self.imageViewB.frame, -width, 0);
}
completion:^(BOOL finished) {
__strong typeof(self) self = self_;
if (self.keepGoing) {
// now B is where A began, so swap them and reposition B
UIImageView *temp = self.imageViewA;
self.imageViewA= self.imageViewB;
self.imageViewB = temp;
self.imageViewB.frame = CGRectOffset(self.view.bounds,
self.view.bounds.size.width, 0.0);
// recursive call, but we don't want to wind up the stack
;
}
}];
}
</code></pre>
<p>这样做是保持对 self 的弱引用,而不是将其复制到 block 中到堆栈中。我不确定,但也许这可以工作。 </p></p>
<p style="font-size: 20px;">关于iphone - 用 Time Profiler 分析的审查方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15355453/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15355453/
</a>
</p>
页:
[1]