Hot to turn to specific page?

71 views
Skip to first unread message

Enterprise application with flex

unread,
Jul 16, 2011, 4:50:18 AM7/16/11
to Leaves Developers
this is a great project,can someone tell me how to turn to specific
page with Leaves

marty

unread,
Apr 25, 2012, 8:07:11 PM4/25/12
to leaves-d...@googlegroups.com
I'm trying to figure this out too.  I assume you mean you want to turn the page programmatically.  I ended up just saving the parameters passed to touchesBegan and touchesEnded in my leavesView, then calling those methods and passing the saved parameters to turn the page.  i guess if you did that multiple times it would keep turning pages.  I added this to the LeavesViewDelegate protocol:

-(void)setTouchSet:(NSSet*)theSet;
-(void)setTouchEvent:(UIEvent*)theEvent;
-(void)setTouchDoneSet:(NSSet*)theDoneSet;
-(void)setTouchDoneEvent:(UIEvent*)theDoneEvent;


and then added the properties "touchSet", "touchEvent", "touchDoneSet", and "touchDoneEvent" to the delegate, and @synthesize them.  then i call:

[delegate setTouchSet:touches];
[delegate setTouchEvent:event];

in leavesView's "touchesBegan".  Then call:

[delegate setTouchDoneSet:touches];
[delegate setTouchDoneEvent:event];

in leavesView's "touchesEnded".  then when you want it to turn pages, you can call leavesView's touchesBegan and touchesEnded:

if(self.touchSet && self.touchEvent)
{
    [_leavesView touchesBegan:self.touchSet withEvent:self.touchEvent];
    [_leavesView touchesEnded:self.touchDoneSet withEvent:self.touchDoneEvent];
}

except i'm having problems with it turning the right way.  it's a work in progress.  hope that helps though!

-marty 

marty

unread,
Apr 25, 2012, 9:41:33 PM4/25/12
to leaves-d...@googlegroups.com
Okay what I ended up doing was swapping this code in [LeavesView touchesBegan:withEvent:]:

UITouch *touch = [event.allTouches anyObject];
touchBeganPoint = [touch locationInView:self];

with this:

if(touches == nil)
{
    BOOL ipad = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
    touchBeganPoint = CGPointMake(ipad ? 750 : 300, ipad ? 512 : 160);
}
else
{
    UITouch *touch = [event.allTouches anyObject];
    touchBeganPoint = [touch locationInView:self];

and add a check to see if touches is nil on this line:

else if (([self touchedNextPage] && [self hasNextPage]) || touches == nil)


and then add this at the end of the method:

if(touches == nil)
    [self touchesEnded:nil withEvent:nil]; 

then in [LeavesView touchesEnded:withEvent:] swap in this:

UITouch *touch = [event.allTouches anyObject];
CGPoint touchPoint;
if(touches == nil)
{
    BOOL ipad = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
    touchPoint = CGPointMake(ipad ? 750 : 300, ipad ? 512 : 160);
}
else
    touchPoint = [touch locationInView:self];
BOOL dragged = distance(touchPoint, touchBeganPoint) > [self dragThreshold];

and check if touches is nil by swapping in this line:

if (((dragged && self.leafEdge < 0.5) || (!dragged && [self touchedNextPage])) || touches == nil) { 
 
Then you can just call [_leavesView touchesBegan:nil withEvent:nil] and it'll turn the page!

On Saturday, July 16, 2011 1:50:18 AM UTC-7, Enterprise application with flex wrote:
Reply all
Reply to author
Forward
0 new messages