Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何设置TTLauncher视图中的最大页数?_Iphone_Cocoa Touch_Uiscrollview_Three20_Ttlauncherview - Fatal编程技术网

Iphone 如何设置TTLauncher视图中的最大页数?

Iphone 如何设置TTLauncher视图中的最大页数?,iphone,cocoa-touch,uiscrollview,three20,ttlauncherview,Iphone,Cocoa Touch,Uiscrollview,Three20,Ttlauncherview,我使用ttlauncheview作为我的应用程序的主屏幕,我只有一页的图标。如何使TTLauncherView不允许您将图标拖动到“下一页”?我想设置最大页数(在本例中为一页) (编辑:长话短说,我对开始编辑进行了子分类,请参见下面的答案。) 我明白了为什么在调用beginEditing时它会添加一个额外的页面,但我不想编辑框架代码。(这使得更新到新版本变得很困难。)如果我必须依赖于它的实现方式,我也不希望对该方法进行子类化和重写。(如果类别是干净的,我不反对子类化或添加类别。) 我尝试在我的T

我使用
ttlauncheview
作为我的应用程序的主屏幕,我只有一页的图标。如何使TTLauncherView不允许您将图标拖动到“下一页”?我想设置最大页数(在本例中为一页)

(编辑:长话短说,我对
开始编辑进行了子分类,请参见下面的答案。

我明白了为什么在调用
beginEditing
时它会添加一个额外的页面,但我不想编辑框架代码。(这使得更新到新版本变得很困难。)如果我必须依赖于它的实现方式,我也不希望对该方法进行子类化和重写。(如果类别是干净的,我不反对子类化或添加类别。)

我尝试在我的
TTLauncherViewDelegate
中的回调方法
launcherViewDidBeginEditing
中将
scrollView.scrollEnabled
设置为否,但在编辑模式下不起作用,我不知道为什么

我试图通过设置
userInteractionEnabled=NO
,在scrollview中添加一个拦截器UIView来拦截触摸事件,该设置正常。我仍然必须以某种方式禁用将
ttlauncheitems
拖动到下一页

我还尝试将scrollview的
contentSize
设置为
LauncherViewDiBeginediting
中的
bounds
,但这似乎也不起作用

有更好的办法吗

试图阻止手势:

- (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;
        }
    }
供参考:

- (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];
    }
}

我认为在
ttlauncher视图中重写
beginEditing
是最好的选择。因为您实际上只涉及一个方法(该方法中只有几行),所以在时机成熟时升级它应该不会太糟糕。由于该方法显式地添加了额外的页面,我不确定您将如何绕过它,而不必像Andrew Flynn在回答中所建议的那样编辑特定的代码块,我可以通过子类化和重写
beginEditing
方法来删除进入编辑模式时添加的额外页面
TTLauncherView
,从而使其正常工作

我遇到的一个问题是,我不知道如何删除在我的子类上调用(private)方法
updateContentSize
时得到的警告。我尝试将其强制转换为
id
,但这并没有删除警告。可能吗

edit:我可以通过使用
performSelector
将消息发送到私有类来删除警告。(我以前创建了一个category方法
performSelector:withInt
,它包装了
NSInvocation
,这样我就可以通过
performSelector
方法传递原语,这使得这非常方便。)

//MyLauncherView.h
@接口MyLauncherView:TTLauncherView{
NSInteger_maxPages;
}
@属性(非原子)NSInteger maxPages;
@结束
//MyLauncherView.m
@实现MyLauncherView
@合成maxPages=\u maxPages;
-(无效)开始编辑{
[超级开始编辑];
//忽略未设置的或负数的页面

if(self.maxPages)有时你只需要被告知你已经知道的,我想。工作起来很有魅力,结果证明没有我想象的那么痛苦。我添加了一个答案,但我认为这个答案是正确的。
// 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];

    }
}