Skip to content

Commit

Permalink
Add swift type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Epain committed Sep 26, 2015
1 parent 60d2c8c commit b6dd72b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 50 deletions.
25 changes: 10 additions & 15 deletions MXSegmentedPager/MXPagerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (void)layoutSubviews {

CGRect frame = self.bounds;
//Layout content view
frame.origin = CGPointMake(0, 0);
frame.origin = CGPointZero;
frame.size.width += self.gutterWidth;
self.contentView.frame = frame;

Expand All @@ -69,15 +69,11 @@ - (void)layoutSubviews {
[self setContentIndex:_index animated:NO];

//Layout loaded pages
frame.size = self.bounds.size;
for (NSNumber *key in self.pages) {
NSInteger index = [key integerValue];
UIView *page = self.pages[key];

page.frame = (CGRect) {
.origin.x = frame.size.width * index,
.origin.y = 0,
.size = self.bounds.size
};
frame.origin.x = self.contentView.bounds.size.width * [key integerValue];
page.frame = frame;
}

[super layoutSubviews];
Expand Down Expand Up @@ -137,6 +133,8 @@ - (__kindof UIView *)dequeueReusablePageWithIdentifier:(NSString *)identifier {
}

id builder = self.registration[identifier];
NSAssert(builder, @"unable to dequeue a page with identifier %@ - must register a nib or a class for the identifier", identifier);

UIView *page = nil;

if ([builder isKindOfClass:[UINib class]]) {
Expand All @@ -146,8 +144,6 @@ - (__kindof UIView *)dequeueReusablePageWithIdentifier:(NSString *)identifier {
page = [[NSClassFromString(builder) alloc] init];
}

NSAssert(page, @"unable to dequeue a page with identifier %@ - must register a nib or a class for the identifier", identifier);

page.reuseIdentifier = identifier;
[self.reuseQueue addObject:page];
[page prepareForReuse];
Expand Down Expand Up @@ -264,11 +260,10 @@ - (void) loadPageAtIndex:(NSInteger) index {
UIView *page = [self.dataSource pagerView:self viewForPageAtIndex:index];
[self.contentView addSubview:page];
[self.pages setObject:page forKey:key];
page.frame = (CGRect) {
.origin.x = self.contentView.bounds.size.width * index,
.origin.y = 0.f,
.size = self.bounds.size
};
//Layout page
CGRect frame = self.bounds;
frame.origin = CGPointMake(self.contentView.bounds.size.width * index, 0);
page.frame = frame;
}
}
};
Expand Down
40 changes: 20 additions & 20 deletions MXSegmentedPager/MXSegmentedPager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@param segmentedPager A segmented-pager object informing the delegate about the impending selection.
@param view The selected page view.
*/
- (void) segmentedPager:(MXSegmentedPager*)segmentedPager didSelectView:(UIView*)view;
- (void) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager didSelectView:(nonnull UIView*)view;

/**
Tells the delegate that a specified title is about to be selected.
@param segmentedPager A segmented-pager object informing the delegate about the impending selection.
@param title The selected page title.
*/
- (void) segmentedPager:(MXSegmentedPager*)segmentedPager didSelectViewWithTitle:(NSString*)title;
- (void) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager didSelectViewWithTitle:(nonnull NSString*)title;

/**
Tells the delegate that a specified index is about to be selected.
@param segmentedPager A segmented-pager object informing the delegate about the impending selection.
@param index The selected page index.
*/
- (void) segmentedPager:(MXSegmentedPager*)segmentedPager didSelectViewWithIndex:(NSInteger)index;
- (void) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager didSelectViewWithIndex:(NSInteger)index;

/**
Asks the delegate to return the height of the segmented control in the segmented-pager.
Expand All @@ -81,7 +81,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return A nonnegative floating-point value that specifies the height (in points) that segmented-control should be.
*/
- (CGFloat) heightForSegmentedControlInSegmentedPager:(MXSegmentedPager*)segmentedPager;
- (CGFloat) heightForSegmentedControlInSegmentedPager:(nonnull MXSegmentedPager*)segmentedPager;

@end

Expand All @@ -101,7 +101,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return The number of pages in segmented-pager.
*/
- (NSInteger) numberOfPagesInSegmentedPager:(MXSegmentedPager *)segmentedPager;
- (NSInteger) numberOfPagesInSegmentedPager:(nonnull MXSegmentedPager *)segmentedPager;

/**
Asks the data source for a view to insert in a particular page of the segmented-pager.
Expand All @@ -111,7 +111,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return An object inheriting from UIView that the segmented-pager can use for the specified page.
*/
- (UIView*) segmentedPager:(MXSegmentedPager*)segmentedPager viewForPageAtIndex:(NSInteger)index;
- (nonnull __kindof UIView*) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager viewForPageAtIndex:(NSInteger)index;

@optional

Expand All @@ -123,7 +123,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return The NSString title of the page in segmented-pager.
*/
- (NSString*) segmentedPager:(MXSegmentedPager*)segmentedPager titleForSectionAtIndex:(NSInteger)index;
- (nonnull NSString*) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager titleForSectionAtIndex:(NSInteger)index;

/**
Asks the data source for a title to assign to a particular page of the segmented-pager. The title will be used depending on the HMSegmentedControlType you have choosen.
Expand All @@ -133,7 +133,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return The NSAttributedString title of the page in segmented-pager.
*/
- (NSAttributedString*) segmentedPager:(MXSegmentedPager*)segmentedPager attributedTitleForSectionAtIndex:(NSInteger)index;
- (nonnull NSAttributedString*) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager attributedTitleForSectionAtIndex:(NSInteger)index;

/**
Asks the data source for a image to assign to a particular page of the segmented-pager. The image will be used depending on the HMSegmentedControlType you have choosen.
Expand All @@ -143,7 +143,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return The image of the page in segmented-pager.
*/
- (UIImage*) segmentedPager:(MXSegmentedPager*)segmentedPager imageForSectionAtIndex:(NSInteger)index;
- (nonnull UIImage*) segmentedPager:(nonnull MXSegmentedPager*)segmentedPager imageForSectionAtIndex:(NSInteger)index;

@end

Expand All @@ -155,32 +155,32 @@ typedef void (^MXProgressBlock) (CGFloat progress);
/**
Delegate instance that adopt the MXSegmentedPagerDelegate.
*/
@property (nonatomic, assign) id<MXSegmentedPagerDelegate> delegate;
@property (nonatomic, weak) id<MXSegmentedPagerDelegate> delegate;

/**
Data source instance that adopt the MXSegmentedPagerDataSource.
*/
@property (nonatomic, assign) id<MXSegmentedPagerDataSource> dataSource;
@property (nonatomic, weak) id<MXSegmentedPagerDataSource> dataSource;

/**
The segmented control. cf. [HMSegmentedControl](http://cocoadocs.org/docsets/HMSegmentedControl/1.5/) for customazation.
*/
@property (nonatomic, readonly) HMSegmentedControl* segmentedControl;
@property (nonatomic, readonly, nonnull) HMSegmentedControl* segmentedControl;

/**
The segmented control position option.
*/
@property (nonatomic, assign) MXSegmentedControlPosition segmentedControlPosition;
@property (nonatomic) MXSegmentedControlPosition segmentedControlPosition;

/**
The pager. The pager will be placed above or below the segmented control depending on the segmentedControlPosition property.
*/
@property (nonatomic, readonly) MXPagerView* pager;
@property (nonatomic, readonly, nonnull) MXPagerView* pager;

/**
The padding from the top, left, right, and bottom of the segmentedControl
*/
@property (nonatomic, assign) UIEdgeInsets segmentedControlEdgeInsets;
@property (nonatomic) UIEdgeInsets segmentedControlEdgeInsets;

/**
Reloads everything from scratch. redisplays pages.
Expand All @@ -205,17 +205,17 @@ typedef void (^MXProgressBlock) (CGFloat progress);
/**
The parallax header. cf. [VGParallaxHeader](http://cocoadocs.org/docsets/VGParallaxHeader/0.0.6/) for more details.
*/
@property (nonatomic, strong, readonly) VGParallaxHeader *parallaxHeader;
@property (nonatomic, strong, readonly, nonnull) VGParallaxHeader *parallaxHeader;

/**
The minimum header height, the header won't scroll below this value. By default, the minimum height is set to 0.
*/
@property (nonatomic, assign) CGFloat minimumHeaderHeight;
@property (nonatomic) CGFloat minimumHeaderHeight;

/**
The progress block called when scroll is progressing.
*/
@property (nonatomic, strong) MXProgressBlock progressBlock;
@property (nonatomic, strong, nullable) MXProgressBlock progressBlock;

/**
Sets the parallax header view.
Expand All @@ -224,7 +224,7 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@param mode The parallax header mode. cf. [VGParallaxHeader](http://cocoadocs.org/docsets/VGParallaxHeader/0.0.6/) for more details.
@param height The header height.
*/
- (void)setParallaxHeaderView:(UIView *)view
- (void)setParallaxHeaderView:(nonnull __kindof UIView *)view
mode:(VGParallaxHeaderMode)mode
height:(CGFloat)height;
@end
Expand All @@ -243,6 +243,6 @@ typedef void (^MXProgressBlock) (CGFloat progress);
@return YES to allow segmented-pager and view to scroll together. The default implementation returns YES.
*/
- (BOOL) segmentedPager:(MXSegmentedPager *)segmentedPager shouldScrollWithView:(UIView*)view;
- (BOOL) segmentedPager:(nonnull MXSegmentedPager *)segmentedPager shouldScrollWithView:(nonnull __kindof UIView*)view;

@end
9 changes: 4 additions & 5 deletions MXSegmentedPager/MXSegmentedPager.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ - (void)layoutSubviews {
[self reloadData];
}

CGRect frame = self.bounds;
//Layout content view
self.contentView.frame = (CGRect) {
.origin = CGPointZero,
.size = self.bounds.size
};
frame.origin = CGPointZero;
self.contentView.frame = frame;

CGRect frame;
//Layout control
frame.origin = (self.segmentedControlPosition == MXSegmentedControlPositionTop)?
CGPointMake(self.segmentedControlEdgeInsets.left, self.segmentedControlEdgeInsets.top) :
CGPointMake(self.segmentedControlEdgeInsets.left, self.bounds.size.height - _controlHeight - self.segmentedControlEdgeInsets.bottom);
Expand Down
8 changes: 4 additions & 4 deletions MXSegmentedPager/MXSegmentedPagerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@return An object inheriting from UIViewController that the segmented-pager can use for the specified page.
*/
- (UIViewController *)segmentedPager:(MXSegmentedPager *)segmentedPager viewControllerForPageAtIndex:(NSInteger)index;
- (nonnull __kindof UIViewController *)segmentedPager:(nonnull MXSegmentedPager *)segmentedPager viewControllerForPageAtIndex:(NSInteger)index;

/**
Asks the data source for a segue identifier to insert in a particular page of the segmented-pager.
Expand All @@ -46,7 +46,7 @@
@return The segue identifier that the segmented-pager can use for the specified page.
*/
- (NSString *)segmentedPager:(MXSegmentedPager *)segmentedPager segueIdentifierForPageAtIndex:(NSInteger)index;
- (nonnull NSString *)segmentedPager:(nonnull MXSegmentedPager *)segmentedPager segueIdentifierForPageAtIndex:(NSInteger)index;

@end

Expand All @@ -58,14 +58,14 @@
/**
Returns the segmengted-pager view managed by the controller object.
*/
@property (nonatomic, strong) MXSegmentedPager *segmentedPager;
@property (nonatomic, strong, readonly, nonnull) MXSegmentedPager *segmentedPager;

@end

/**
Default string identifier format to be applied to segues on a storyboard
*/
extern NSString* const MXSeguePageIdentifierFormat; // @"mx_page_%ld"
extern NSString* _Nonnull const MXSeguePageIdentifierFormat; // @"mx_page_%ld"

/**
The MXPageSegue class creates a segue object to get pages from storyboard.
Expand Down
9 changes: 3 additions & 6 deletions MXSegmentedPager/MXSegmentedPagerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@

@interface MXSegmentedPagerController ()
@property (nonatomic,weak) UIViewController *pageViewController;
@property (nonatomic,assign) NSInteger pageIndex;
@property (nonatomic) NSInteger pageIndex;
@end

@implementation MXSegmentedPagerController

@synthesize segmentedPager = _segmentedPager;

- (void)loadView {
self.view = self.segmentedPager;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
self.segmentedPager = nil;
}

#pragma mark Properties

- (UIView *)segmentedPager {
Expand Down

0 comments on commit b6dd72b

Please sign in to comment.