Open iamcam opened 13 years ago
Makes sense. Animating the icons on-to and off-of these UIScrollViews could be complicated.
Perhaps focus on a vertical scroll version first. If anything a user can reposition the view vertically and keep moving until satisfied with the position.
I know 320 does it, but I confess I don't fully understand that level of programming. I don't think they're using UITableView-like classes and methods, either, so that might be part of it.
They subclass UIScrollView, but we wont need to: this openspringboard code works on UIView containers and it doesn't matter whether that container is static or stuffed within a UIScrollView. The delegate methods should eventually take as input your UIView, and then insert either the icon/text/badge containers or a UIScrollView with those containers as subviews. The easiest way to do this would be for us to have a parameter to specify the maximum number of icons per UIView, and deduce UIScrollView "panel" counts from that.
just add some tags so you can handle the data call backs
the delete icons is going to bomb for now.
numberOfPages = 2; _openSpringBoard = [[OpenSpringBoard alloc] init]; _openSpringBoard.tag = 1; _openSpringBoard.delegate = self; [_openSpringBoard.view setFrame:CGRectMake(0, 0, 320, 480-44-20)];
_openSpringBoard2 = [[OpenSpringBoard alloc] init];
_openSpringBoard2.tag = 2;
_openSpringBoard2.delegate = self;
[_openSpringBoard2.view setFrame:CGRectMake(320, 0, 320, 480-44-20)];
mySV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-44-20)];
[mySV addSubview:_openSpringBoard.view];
[mySV addSubview:_openSpringBoard2.view];
[mySV setPagingEnabled:YES];
[mySV setDelegate:self];
[self.view addSubview:mySV];
[mySV setContentSize:CGSizeMake(numberOfPages*320, 480-44-20)];
if (openSringBoardVC.tag ==1) do page 1 icons.
etc
boom
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(160-40,480-44-20-40, 80.0, 20.0)];
[pageControl addTarget:self action:@selector(:) forControlEvents:UIControlEventTouchUpInside];
pageControl.numberOfPages = 2; // must be set or control won't draw
// in case the parent view draws with a custom color or gradient, use a transparent color
pageControl.backgroundColor = [UIColor clearColor];
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
pageControl.currentPage = [self determineIndexFromCurrentScroll];
}
-(NSUInteger)determineIndexFromCurrentScroll{
ENTER_METHOD;
float w = mySV.contentSize.width/ numberOfPages;
CGPoint pt = [mySV contentOffset];
CGFloat x = pt.x / w;
return (int) x;
}
Thanks, John. I like your approach. We've been debating whether to support landscape mode & then how to handle moving icons between different pages. Any recommendations?
let's hold back on the landscape mode.
in the apple sample code for "Autoscroll" from wwdc / scroll view suite, there's some code and in movie the guys steps through logic for handling long holds and responding to this gesture when icon hits side of the screen.
This multi page containers is going to be a royal head ache to cross this logic over into different views. They are each going to need to talk to each other - and is going to have a lot of wiring necessary for each page.
it's probably better not to go down this path that I've started. For me - it gets the job done for now. It would so much easier if they were all in one view which spands multiple pages within the one uiscrollview.
if icons being added go beyond (iconsPerPage) > then offset the new ones by device screen width * pageNumber and reset the y position.
then you wont need to change the existing moving logic - just handle events when we hit the sides of the screen.
It would be great to have support for either a continuous vertical scroll or paged left/right as Springboard does it