[英]Reviewing Method Analyzed with Time Profiler
我已經使用了Time Profiler Instrument來識別我的應用程序中的明顯滯后。 現在我知道了問題所在,但是我不知道該怎么辦。 我正在使用ARC,並且有一個viewController,它調用方法“ Go”,如下所示。 我還包括了時間分析器結果的快照。 有誰知道我該怎么解決? 謝謝!
這是該方法的代碼:
- (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
[self performSelector:@selector(go) withObject:nil afterDelay:0.0];
}
}];
}
這是我的時間檔案的結果:
作為參考,我也包括了我的.h文件。
@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
也許這可以工作:
- (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
[self performSelector:@selector(go) withObject:nil afterDelay:0.0];
}
}];
}
這樣做是保持對self的弱引用,而不是將其復制到塊中的堆棧中。 我不確定,但是也許可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.