0

我正在TTLauncherView用作我的应用程序的一种主屏幕,我只有一页的图标。我怎样才能做到这一点,以便 TTLauncherView 不会让您将图标拖到“下一页”?我想设置最大页数(在本例中为一页。)

(编辑: 长话短说,我分类beginEditing了,见下面的答案。)

我知道为什么它在beginEditing调用时会添加一个额外的页面,但我不想编辑框架代码。(这使得更新到较新的版本变得困难。)如果我必须依赖它的实现方式,我也不想继承和覆盖那个方法。(如果它是干净的,我不反对子类化或添加一个类别。)

我尝试在我scrollView.scrollEnabled的回调方法中设置为 NO ,但是在它处于编辑模式时不起作用,我不知道为什么。launcherViewDidBeginEditingTTLauncherViewDelegate

我尝试在滚动视图中添加一个拦截器 UIView 以通过设置来拦截触摸事件userInteractionEnabled=NO,这可以正常工作。我仍然必须以TTLauncherItems某种方式禁用拖动到下一页。

我也尝试将contentSize滚动视图的设置为boundsin 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];
    }
}
4

2 回答 2

2

我认为压倒一切beginEditingTTLauncherView你最好的选择。由于您只会真正接触一种方法(并且该方法中只有几行),因此在时机成熟时升级它应该不会太糟糕。由于该方法显式添加了额外的页面,因此我不确定在不编辑该特定代码的情况下如何解决它

于 2011-04-14T21:58:31.197 回答
0

正如 Andrew Flynn 在他的回答中所建议的那样,我能够通过子类化和覆盖在进入编辑模式时beginEditing删除额外页面添加的方法来使其工作。TTLauncherView

我遇到的一个问题是我无法弄清楚如何删除因updateContentSize在子类上调用(私有)方法而收到的警告。我尝试将其转换为id,但这并没有消除警告。可能吗?

编辑:我能够通过使用performSelector将消息发送到私人课程来删除警告。(我之前创建了一个performSelector:withInt包装的类别方法,NSInvocation以便我可以通过performSelector方法传递原语,这使得这非常方便。)

// MyLauncherView.h
@interface MyLauncherView : TTLauncherView {
    NSInteger _maxPages;
}

@property (nonatomic) NSInteger maxPages;

@end




// MyLauncherView.m
@implementation MyLauncherView
@synthesize maxPages = _maxPages;

- (void)beginEditing {
    [super beginEditing];

    // ignore unset or negative number of pages
    if (self.maxPages <= 0) {
        return;
    }

    // if we've got the max number of pages, remove the extra "new page" that is added in [super beginEditing]
    if ([_pages count] >= self.maxPages ) {
        [_pages removeLastObject];

        [self updateContentSize:_pages.count];   // this has a compiler warning

        // I added this method to NSObject via a category so I can pass primitives with performSelector
        // [self performSelector:@selector(updateContentSize:) withInt:_pages.count waitUntilDone:NO];

    }
}
于 2011-04-14T22:34:48.237 回答