• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - 用 Time Profiler 分析的审查方法

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:33:30 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我已使用 Time Profiler Instrument 来识别我的应用程序中的显着滞后。现在我知道问题出在哪里,但我不知道该怎么办。我正在使用 ARC 并有一个 viewController 调用方法“Go”,如下所示。我还包含了 Time Profiler 结果的快照。有谁知道我该如何解决这个问题?谢谢!

这是方法的代码:

- (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 performSelectorselector(go) withObject:nil afterDelay:0.0];
        }
    }];
}

这是我的时间文件的结果:

enter image description here

作为引用,我还包含了我的 .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)handleLPressedid)sender;
- (IBAction)handleRPressedid)sender;
@end



Best Answer-推荐答案


也许这可以工作:

- (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 performSelectorselector(go) withObject:nil afterDelay:0.0];
        }
    }];
}

这样做是保持对 self 的弱引用,而不是将其复制到 block 中到堆栈中。我不确定,但也许这可以工作。

关于iphone - 用 Time Profiler 分析的审查方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15355453/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap