Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Fixed bug @1016: Calculate edges correctly when touching screen dur…

…ing animation
  • Loading branch information...
commit 0de57f55e02d50d01b6c772585a58a7df680be93 1 parent 1c16257
@joehewitt joehewitt authored
View
3  project.dev
@@ -0,0 +1,3 @@
+
+name = "Three20"
+description = "Three20 iPhone Framework"
View
10 src/T3PhotoViewController.m
@@ -386,11 +386,6 @@ - (void)reloadContent {
- (void)updateView {
if (![self.previousViewController isKindOfClass:[T3ThumbsViewController class]]) {
- UIBarButtonItem* playButton = [_toolbar itemWithTag:1];
- playButton.enabled = _photoSource.numberOfPhotos > 1;
- _previousButton.enabled = _centerPhotoIndex > 0;
- _nextButton.enabled = _centerPhotoIndex < _photoSource.numberOfPhotos-1;
-
if (_photoSource.numberOfPhotos > 1) {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"See All", @"See all photo thumbnails")
@@ -402,6 +397,11 @@ - (void)updateView {
self.navigationItem.rightBarButtonItem = nil;
}
+ UIBarButtonItem* playButton = [_toolbar itemWithTag:1];
+ playButton.enabled = _photoSource.numberOfPhotos > 1;
+ _previousButton.enabled = _centerPhotoIndex > 0;
+ _nextButton.enabled = _centerPhotoIndex < _photoSource.numberOfPhotos-1;
+
_scrollView.centerPageIndex = _centerPhotoIndex;
[self loadImages];
View
67 src/T3ScrollView.m
@@ -186,6 +186,14 @@ - (CGRect)frameOfPageAtIndex:(NSInteger)pageIndex {
return CGRectMake(-xd/2, -yd/2, width, height);
}
+- (CGFloat)overflowForFrame:(CGRect)frame {
+ if (UIInterfaceOrientationIsLandscape(_orientation)) {
+ return frame.origin.y < 0 ? fabs(frame.origin.y) : 0;
+ } else {
+ return frame.origin.x < 0 ? fabs(frame.origin.x) : 0;
+ }
+}
+
- (CGPoint)offsetForOrientation:(CGFloat)x y:(CGFloat)y {
if (UIInterfaceOrientationIsLandscape(_orientation)) {
return CGPointMake(y, x);
@@ -324,13 +332,20 @@ - (void)enqueueAllPages {
}
- (void)adjustPageEdgesForPageAtIndex:(NSInteger)pageIndex {
+ CGRect centerFrame = [self frameOfPageAtIndex:_centerPageIndex];
+ CGFloat centerPageOverflow = [self overflowForFrame:centerFrame] * self.zoomFactor;
+ CGRect frame = [self frameOfPageAtIndex:pageIndex];
+ CGFloat overflow = [self overflowForFrame:frame];
+
if (self.flipped) {
- CGFloat xd = (_centerPageIndex - pageIndex) * -(self.pageWidth + _pageSpacing);
+ CGFloat factor = _centerPageIndex > pageIndex ? -1 : 1;
+ CGFloat xd = (self.pageWidth + _pageSpacing + centerPageOverflow + overflow) * factor;
CGFloat left = _pageEdges.right > 0 ? _pageEdges.right : _pageEdges.left;
CGFloat right = _pageEdges.left < 0 ? _pageEdges.left : _pageEdges.right;
_pageEdges = _pageStartEdges = UIEdgeInsetsMake(0, left - xd, 0, right - xd);
} else {
- CGFloat xd = (_centerPageIndex - pageIndex) * (self.pageWidth + _pageSpacing);
+ CGFloat factor = _centerPageIndex > pageIndex ? 1 : -1;
+ CGFloat xd = (self.pageWidth + _pageSpacing + centerPageOverflow + overflow) * factor;
CGFloat left = _pageEdges.right < 0 ? _pageEdges.right : _pageEdges.left;
CGFloat right = _pageEdges.left > 0 ? _pageEdges.left : _pageEdges.right;
_pageEdges = _pageStartEdges = UIEdgeInsetsMake(0, right - xd, 0, left - xd);
@@ -370,10 +385,6 @@ - (void)moveToPageAtIndex:(NSInteger)pageIndex resetEdges:(BOOL)resetEdges {
_pageArrayIndex = [self arrayIndexForPageIndex:pageIndex relativeToIndex:_centerPageIndex];
_centerPageIndex = pageIndex;
}
-
- // XXXjoe Move the center page to to the top of the views - temporary fix until
- // I work out how to clip photos
- [self addSubview:self.centerPage];
}
- (void)layoutPage {
@@ -398,14 +409,6 @@ - (void)layoutPage {
}
}
-- (CGFloat)overflowForFrame:(CGRect)frame {
- if (UIInterfaceOrientationIsLandscape(_orientation)) {
- return frame.origin.y < 0 ? fabs(frame.origin.y) : 0;
- } else {
- return frame.origin.x < 0 ? fabs(frame.origin.x) : 0;
- }
-}
-
- (void)layoutAdjacentPages {
BOOL flipped = self.flipped;
BOOL pinched = self.pinched;
@@ -553,11 +556,12 @@ - (UIEdgeInsets)constrainEdges:(UIEdgeInsets)edges toWidth:(CGFloat)constrainedW
edges.bottom + yd/2, edges.right + xd/2);
}
-- (CGFloat)mm:(CGFloat)m1 t:(CGFloat)m2 max:(CGFloat)max {
- CGFloat rl = (1 - (fabs(m2) / max)) * 0.1;
- if (rl < 0) rl = 0;
- if (rl > 1) rl = 1;
- return m1 + ((m2 - m1) * rl);
+- (CGFloat)resist:(CGFloat)x1 to:(CGFloat)x2 max:(CGFloat)max {
+ // The closer we get to the maximum, the less we are allowed to increment
+ CGFloat rl = (1 - (fabs(x2) / max)) * 0.1;
+ if (rl < 0) rl = 0;
+ if (rl > 1) rl = 1;
+ return x1 + ((x2 - x1) * rl);
}
- (UIEdgeInsets)resistPageEdges:(UIEdgeInsets)edges {
@@ -566,14 +570,14 @@ - (UIEdgeInsets)resistPageEdges:(UIEdgeInsets)edges {
if (-left + right < 0 || -top + bottom < 0) {
CGFloat zoom = self.zoomFactor;
- left = [self mm:_pageEdges.left t:left max:width * zoom];
- right = [self mm:_pageEdges.right t:right max:width * zoom];
- top = [self mm:_pageEdges.top t:top max:height * zoom];
- bottom = [self mm:_pageEdges.bottom t:bottom max:height * zoom];
+ left = [self resist:_pageEdges.left to:left max:width * zoom];
+ right = [self resist:_pageEdges.right to:right max:width * zoom];
+ top = [self resist:_pageEdges.top to:top max:height * zoom];
+ bottom = [self resist:_pageEdges.bottom to:bottom max:height * zoom];
} else {
if (_touchCount == 2 || self.zoomed) {
if (top > 0) {
- top = [self mm:_pageEdges.top t:top max:height];
+ top = [self resist:_pageEdges.top to:top max:height];
if (_touchCount == 2) {
bottom = bottom + (top - _pageEdges.top);
} else {
@@ -586,7 +590,7 @@ - (UIEdgeInsets)resistPageEdges:(UIEdgeInsets)edges {
left -= xd/2;
right += xd/2;
} else if (bottom < 0) {
- bottom = [self mm:_pageEdges.bottom t:bottom max:height];
+ bottom = [self resist:_pageEdges.bottom to:bottom max:height];
if (_touchCount == 2) {
top = top + (bottom - _pageEdges.bottom);
} else {
@@ -601,8 +605,11 @@ - (UIEdgeInsets)resistPageEdges:(UIEdgeInsets)edges {
}
}
- if (left > 0 && ([self isFirstPage] || self.zoomed)) {
- left = [self mm:_pageEdges.left t:left max:width];
+ BOOL flipped = self.flipped;
+ BOOL flickPrevious = (left > 0 && !flipped) || (left < 0 && flipped);
+ BOOL flickNext = (right < 0 && !flipped) || (right > 0 && flipped);
+ if (flickPrevious && ([self isFirstPage] || self.zoomed)) {
+ left = [self resist:_pageEdges.left to:left max:width];
if (_touchCount == 2) {
right = right + (left - _pageEdges.left);
} else {
@@ -614,8 +621,8 @@ - (UIEdgeInsets)resistPageEdges:(UIEdgeInsets)edges {
CGFloat yd = newHeight - (-top + height + bottom);
top -= yd/2;
bottom += yd/2;
- } else if (right < 0 && ([self isLastPage] || self.zoomed)) {
- right = [self mm:_pageEdges.right t:right max:width];
+ } else if (flickNext && ([self isLastPage] || self.zoomed)) {
+ right = [self resist:_pageEdges.right to:right max:width];
if (_touchCount == 2) {
left = left + (right - _pageEdges.right);
} else {
@@ -1017,7 +1024,7 @@ - (void)setDataSource:(id<T3ScrollViewDataSource>)dataSource {
}
- (void)setCenterPageIndex:(NSInteger)index {
- [self moveToPageAtIndex:index resetEdges:YES];
+ [self moveToPageAtIndex:index resetEdges:!_touchCount];
}
- (NSInteger)numberOfPages {
View
3  src/T3ThumbsViewController.m
@@ -10,6 +10,7 @@
static NSInteger kColumnCount = 4;
static NSInteger kPageSize = 60;
+static CGFloat kThumbnailRowHeight = 79;
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -242,7 +243,7 @@ - (UITableViewCell *)tableView:(UITableView*)tableView
// UITableViewDelegate
- (CGFloat)tableView:(UITableView*)aTableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
- return 79;
+ return kThumbnailRowHeight;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
Please sign in to comment.
Something went wrong with that request. Please try again.