我正在开发的 iPad 应用程序是一本书。要跳转到特定页面,用户可以按下一个按钮,该按钮覆盖当前视图的视图顶部,显示书中每个页面的缩略图图像。
当用户按顺序浏览书籍并显示此缩略图菜单时,如果用户显示该菜单,则滚动动画是流畅而精细的。如果用户showBookmarkMenu
在加载大约 15 页后调用,滚动视图动画非常非常慢,并且滚动视图不再捕获触摸,则会出现问题。
我注意到scrollViewDidEndDecelerating
当滚动动画正常且流畅时(加载应用程序后不久)会调用它,但在用户浏览几页后不会调用它。所以一个假设是 CPU 正在努力处理滚动视图内容定位的动画。我使用 Instruments 的 Activity Monitor 运行应用程序,但有时应用程序使用 97% 甚至更多的 CPU 并且滚动视图滚动良好......
对这个问题有什么想法吗?我已经在下面发布了我的代码。
主类.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];
}
}
滚动视图类.h
@interface BookmarkManager : UIView<UIScrollViewDelegate>{
UIScrollView *thumbnailScrollView;
}
@property (strong, nonatomic) UIScrollView *thumbnailScrollView;
@property (strong) id <BookmarkManagerDelegate> bookmarkManagerDelegate;
-(void)showBookmarkMenu;
-(void)hideBookmarksMenu;
@end
滚动视图类.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;
}