gpt4 book ai didi

ios - UIScrollView 滚动太慢,从不调用 scrollViewDidEndDecelerating

转载 作者:行者123 更新时间:2023-11-28 22:51:39 24 4
gpt4 key购买 nike

我正在开发的 iPad 应用程序是一本书。要跳转到特定页面,用户可以按下覆盖当前 View 顶部的按钮,显示书中每一页的缩略图图像。

当用户按顺序浏览这本书并显示这个缩略图菜单时,如果用户显示菜单,则滚动动画是流畅和精细的。如果用户在加载大约十五页后调用 showBookmarkMenu,就会出现问题, ScrollView 动画非常非常慢,并且 ScrollView 不再捕捉触摸。

我注意到 scrollViewDidEndDecelerating 在滚动动画正常且流畅时(加载应用程序后不久)被调用,但在用户浏览多个页面后它不会被调用。因此,一种假设是 CPU 正在努力处理 ScrollView 内容定位的动画。我使用 Instruments 的 Activity Monitor 运行应用程序,但有时应用程序使用 97% 或更多的 CPU,并且 ScrollView 滚动正常......

对这个问题有什么想法吗?我已经在下面发布了我的代码。

MainClass.m

//Called when user presses the open/close bookmark menu button
-(IBAction)toggleBookmarksMenu{
if([bookMarkMenu isHidden]){
[currentPage.view addSubview:bookMarkMenu];
[bookMarkMenu showBookmarkMenu];

}
else{
[bookMarkMenu hideBookmarksMenu];
}
}

ScrollViewClass.h

@interface BookmarkManager : UIView<UIScrollViewDelegate>{
UIScrollView *thumbnailScrollView;
}

@property (strong, nonatomic) UIScrollView *thumbnailScrollView;
@property (strong) id <BookmarkManagerDelegate> bookmarkManagerDelegate;


-(void)showBookmarkMenu;
-(void)hideBookmarksMenu;

@end

ScrollViewClass.m

-(void)showBookmarkMenu{
[self setHidden:NO];
[UIView animateWithDuration:0.5
animations:^{
self.center = CGPointMake(512, 384);
}
];
}


-(void)hideBookmarksMenu{
[UIView animateWithDuration:1
animations:^{
self.center = CGPointMake(512, -120);
}
completion:^(BOOL finished){
[self setHidden:YES];
[self removeFromSuperview];
}
];
}

-(id)init{
self = [super initWithFrame:CGRectMake(0, 0, 1024, 768)];
if(self){
[self setBackgroundColor:[UIColor clearColor]];
self.center = CGPointMake(512, 0);

thumbnailScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 120)];
[thumbnailScrollView setBackgroundColor:[UIColor clearColor]];
thumbnailScrollView.showsHorizontalScrollIndicator = NO;

//Add the UIButtons with images of the thumbnails
for(int i = 0; i < totalPages; i++){

UIButton *pageThumbnail = [UIButton buttonWithType:UIButtonTypeCustom];
pageThumbnail.frame = CGRectMake(0, 0, 125, 95);

[pageThumbnail setBackgroundImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/p%d_thumb.png", [[NSBundle mainBundle] resourcePath], i]] forState:UIControlStateNormal];

[thumbnailScrollView addSubview:pageThumbnail];
[pageThumbnail addTarget:self action:@selector(thumbnailTapped:) forControlEvents:UIControlEventTouchDown];

}

[self addSubview:thumbnailScrollView];
[thumbnailScrollView setContentSize:CGSizeMake(totalPages * 125 + (20*(totalPages+1)), 120)];
[thumbnailScrollView setDelegate:self];

[self setHidden:YES];
}
return self;
}

最佳答案

我必须解决可能的低内存问题。

使用大量按钮的一种可能替代方法是使用 UITableView。您的代码当前的工作方式是,它会加载所有带有图像的按钮。对于一本大书来说,这可能会很痛苦。

使用 UITableView 你只使用你看到的(大约)内存。而且,由于每个图像都是动态加载的,因此您的内存使用量仅与显示的一样多。这就是我的处理方式(实际上,我现在正在这样做,只是不看书)。

关于ios - UIScrollView 滚动太慢,从不调用 scrollViewDidEndDecelerating,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11848988/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com