我正在TTLauncherView
用作我的应用程序的一种主屏幕,我只有一页的图标。我怎样才能做到这一点,以便 TTLauncherView 不会让您将图标拖到“下一页”?我想设置最大页数(在本例中为一页。)
(编辑: 长话短说,我分类beginEditing
了,见下面的答案。)
我知道为什么它在beginEditing
调用时会添加一个额外的页面,但我不想编辑框架代码。(这使得更新到较新的版本变得困难。)如果我必须依赖它的实现方式,我也不想继承和覆盖那个方法。(如果它是干净的,我不反对子类化或添加一个类别。)
我尝试在我scrollView.scrollEnabled
的回调方法中设置为 NO ,但是在它处于编辑模式时不起作用,我不知道为什么。launcherViewDidBeginEditing
TTLauncherViewDelegate
我尝试在滚动视图中添加一个拦截器 UIView 以通过设置来拦截触摸事件userInteractionEnabled=NO
,这可以正常工作。我仍然必须以TTLauncherItems
某种方式禁用拖动到下一页。
我也尝试将contentSize
滚动视图的设置为bounds
in launcherViewDidBeginEditing
,但这似乎也不起作用。
有没有更好的办法?
试图阻止手势:
- (void)setLauncherViewScrollEnabled:(BOOL)scrollEnabled {
if (scrollEnabled) {
[self.scrollViewTouchInterceptor removeFromSuperview];
self.scrollViewTouchInterceptor = nil;
} else {
// iter through the kids to get the scrollview, put a gesturerecognizer view in front of it
UIScrollView *scrollView = [launcherView scrollViewSubview];
self.scrollViewTouchInterceptor = [UIView viewWithFrame:scrollView.bounds]; // property retains it
UIView *blocker = self.scrollViewTouchInterceptor;
[scrollView addSubview:scrollViewTouchInterceptor];
[scrollView sendSubviewToBack:scrollViewTouchInterceptor];
scrollViewTouchInterceptor.userInteractionEnabled = NO;
}
}
供参考:TTLauncherView.m:
- (void)beginEditing {
_editing = YES;
_scrollView.delaysContentTouches = YES;
UIView* prompt = [self viewWithTag:kPromptTag];
[prompt removeFromSuperview];
for (NSArray* buttonPage in _buttons) {
for (TTLauncherButton* button in buttonPage) {
button.editing = YES;
[button.closeButton addTarget:self action:@selector(closeButtonTouchedUpInside:)
forControlEvents:UIControlEventTouchUpInside];
}
}
// Add a page at the end
[_pages addObject:[NSMutableArray array]];
[_buttons addObject:[NSMutableArray array]];
[self updateContentSize:_pages.count];
[self wobble];
if ([_delegate respondsToSelector:@selector(launcherViewDidBeginEditing:)]) {
[_delegate launcherViewDidBeginEditing:self];
}
}