SEssentialsFlowLayout not scrolling horizontally


#1

Hi there,

I was playing with SEssentialsFlowLayout to build a complex view that we require, no matter what i try i just cannot make it scroll horizonatally, I have set the contentsize and anything else i can think of.

is there anything i’m missing? and should be aware of SEssentialsFlowLayout horizontal scrolling aspects?

Thanks for your help.


#2

Any thoughts?

I’m not doing anything fancy,

Just a view which has a SEssentialsFlowLayout as its subview which has a lits of subviews with a frame defined as the full width of the ipad screen and bounds set to 3 times as much as the width of the ipad screen.

App is only designed for ipad and in landscape mode.

appreciate your help.


#3

Bumping this up again,

In a normal scroll view its able to scroll horizontally without any issues change the class to SEssentialsFlowLayout and it just fallsapart.

here is the sample code.

  • (SEssentialsFlowLayout *)getScroll {

//    UIScrollView *allItems = [[UIScrollView alloc] initWithFrame:CGRectMake(12.0f, 22.0f, 320.0f, 78.0f)];

//    [allItems setContentSize:CGSizeMake(_category.itemColors.count *77,78)];

//    CGRect aFrame =  {{0.0f, 0.0f}, {77.0f, 78.0f}};

//    [allItems setPagingEnabled:YES];

//    for (NSString *itemColor in _category.itemColors) {

//        NSLog(@“Frame: %@”, NSStringFromCGRect(aFrame));

//        UIView *item = [[UIView alloc] initWithFrame:aFrame];

//        item.backgroundColor = [UIColor UIColorFromHex:itemColor];

//        [allItems addSubview:item];

//        aFrame = CGRectOffset(aFrame, 77.0f, 0);

//    }

    SEssentialsFlowLayout *allItems = [[SEssentialsFlowLayout alloc] initWithFrame:CGRectMake(12.0f, 22.0f, 320.0f, 78.0f)];

    [allItems setContentSize:CGSizeMake(_category.itemColors.count *77,78)];

    CGRect aFrame =  {{0.0f, 0.0f}, {77.0f, 78.0f}};

    [allItems setPagingEnabled:YES];

    NSLog(@“contentSize–%@”, NSStringFromCGSize(allItems.contentSize));

    for (NSString *itemColor in _category.itemColors) {

//        NSLog(@“Frame: %@”, NSStringFromCGRect(aFrame));

        UIView *item = [[UIView alloc] initWithFrame:aFrame];

        item.backgroundColor = [UIColor UIColorFromHex:itemColor];

        [allItems addSubview:item];

        aFrame = CGRectOffset(aFrame, 77.0f, 0);

    }

    NSLog(@“contentSize–%@”, NSStringFromCGSize(allItems.contentSize));

    return allItems;

}

contentsize seems 

driving me mad :frowning:  is SEssentialsFlowLayout vertical scroll only? 


#4

Greetings Program!

In order to scroll horizontally, you will need to set the flow layout frame width to the maximum width of all items and add it into a scroll view and then add the scroll view to your final view.

One thing to note, if you are in edit mode, you have to scroll to the end to get to the checkmark to exit out of edit mode. You might want to put a button somewhere outside of the scrollview to exit edit mode so you don’t have to do that.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Add a scroll view.
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(12.0f, 22.0f, 1012.0f, 100.0f)];
    [self.view addSubview:scrollView];

    // Add the flow layout to the scroll view.
    SEssentialsFlowLayout *flowLayout = [self getScroll];
    [scrollView addSubview:flowLayout];

    // Set the scroll view content size to the size of the flowLayout content size.
    scrollView.contentSize = CGSizeMake(flowLayout.contentSize.width, flowLayout.contentSize.height);
}

- (SEssentialsFlowLayout *)getScroll {
    NSArray *itemColors = @[@"0x990000",@"0xdcedcf",@"0x008000",@"0xffff00",@"0x800080",@"0xcc3333",@"0xf75b68",@"0x191919",@"0x4c8bff",@"0xfec04c"];

    // Use 100 (or whatever you need) for width and height to account for padding.
    SEssentialsFlowLayout *allItems = [[SEssentialsFlowLayout alloc] initWithFrame:CGRectMake(0.0f, 0.0f, itemColors.count * 100.0f, 100.0f)];
	
    CGRect aFrame = {{0.0f, 0.0f}, {77.0f, 78.0f}};
	
    NSLog(@"contentSize--%@", NSStringFromCGSize(allItems.contentSize));

    for (NSString *itemColor in itemColors) {
// NSLog(@"Frame: %@", NSStringFromCGRect(aFrame));
        UIView *item = [[UIView alloc] initWithFrame:aFrame];
        item.backgroundColor = [self colorFromHex:itemColor];
		
        //[allItems addSubview:item];
        [allItems addManagedSubview:item];
		
        aFrame = CGRectOffset(aFrame, 77.0f, 0);
    }
	
    NSLog(@"contentSize--%@", NSStringFromCGSize(allItems.contentSize));
	
    return allItems;
}

- (UIColor *)colorFromHex:(unsigned long)hex
{
    return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 green:((float)((hex & 0xFF00) >> 8))/255.0 blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
}

Wg