Skip to content

Commit

Permalink
preferredTargetWidth property
Browse files Browse the repository at this point in the history
  • Loading branch information
brow committed Aug 2, 2010
1 parent 2f4d635 commit b4e67df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Leaves/LeavesView.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

CGSize pageSize;
LeavesCache *pageCache;
CGFloat preferredTargetWidth;
BOOL backgroundRendering;

CGPoint touchBeganPoint;
Expand All @@ -44,6 +45,7 @@
@property (assign) id<LeavesViewDataSource> dataSource;
@property (assign) id<LeavesViewDelegate> delegate;
@property (readonly) CGFloat targetWidth;
@property (assign) CGFloat preferredTargetWidth;
@property (assign) NSUInteger currentPageIndex;
@property (assign) BOOL backgroundRendering;

Expand Down
38 changes: 25 additions & 13 deletions Leaves/LeavesView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @interface LeavesView ()
@implementation LeavesView

@synthesize delegate;
@synthesize leafEdge, currentPageIndex, backgroundRendering;
@synthesize leafEdge, currentPageIndex, backgroundRendering, preferredTargetWidth;

- (void) setUpLayers {
self.clipsToBounds = YES;
Expand Down Expand Up @@ -213,13 +213,29 @@ - (CGFloat) dragThreshold {

- (CGFloat) targetWidth {
// Magic empirical formula
return MAX(28, self.bounds.size.width / 5);
if (preferredTargetWidth > 0 && preferredTargetWidth < self.bounds.size.width / 2)
return preferredTargetWidth;
else
return MAX(28, self.bounds.size.width / 5);
}

- (void) updateTargetRects {
CGFloat targetWidth = [self targetWidth];
nextPageRect = CGRectMake(self.bounds.size.width - targetWidth,
0,
targetWidth,
self.bounds.size.height);
prevPageRect = CGRectMake(0,
0,
targetWidth,
self.bounds.size.height);
}

#pragma mark accessors

- (id<LeavesViewDataSource>) dataSource {
return pageCache.dataSource;

}

- (void) setDataSource:(id<LeavesViewDataSource>)value {
Expand Down Expand Up @@ -248,7 +264,12 @@ - (void) setCurrentPageIndex:(NSUInteger)aCurrentPageIndex {
[CATransaction commit];
}

#pragma mark UIView methods
- (void) setPreferredTargetWidth:(CGFloat)value {
preferredTargetWidth = value;
[self updateTargetRects];
}

#pragma mark UIResponder methods

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (interactionLocked)
Expand Down Expand Up @@ -337,16 +358,7 @@ - (void) layoutSubviews {
[CATransaction commit];
pageCache.pageSize = self.bounds.size;
[self getImages];

CGFloat touchRectsWidth = self.bounds.size.width / 7;
nextPageRect = CGRectMake(self.bounds.size.width - touchRectsWidth,
0,
touchRectsWidth,
self.bounds.size.height);
prevPageRect = CGRectMake(0,
0,
touchRectsWidth,
self.bounds.size.height);
[self updateTargetRects];
}
}

Expand Down

0 comments on commit b4e67df

Please sign in to comment.