Skip to content

Commit

Permalink
Add support to nib
Browse files Browse the repository at this point in the history
Add support to nib, just change the class on nib file to
ASHorizontalScrollView
  • Loading branch information
terenceLuffy committed Sep 15, 2016
1 parent 5e1929d commit fa7f835
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 58 deletions.
4 changes: 2 additions & 2 deletions ASHorizontalScrollViewForObjectiveC.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ASHorizontalScrollViewForObjectiveC"
s.version = "1.2"
s.version = "1.3"
s.summary = "App store style horizontal scroll view Objective-C"
s.description = <<-DESC
It acts similar to apps sliding behaviours in App store. There are both Objective-C and Swift version available and they perform exactly the same function, please find whichever you like.
Expand All @@ -20,6 +20,6 @@ Pod::Spec.new do |s|
s.author = { "Weiwei Chen" => "terenceluffy@gmail.com" }
s.platform = :ios, "8.0"
s.ios.deployment_target = "8.0"
s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.2" }
s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.3" }
s.source_files = 'Sources/ASHorizontalScrollView/*'
end
16 changes: 13 additions & 3 deletions ScrollViewSample/ScrollViewSample.xcodeproj/project.pbxproj
Expand Up @@ -221,7 +221,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = SA;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Zuse;
TargetAttributes = {
7402EE06193BB82D00B1C37D = {
Expand Down Expand Up @@ -351,14 +351,19 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -391,13 +396,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -419,7 +429,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ScrollViewSample/ScrollViewSample-Prefix.pch";
INFOPLIST_FILE = "ScrollViewSample/ScrollViewSample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand All @@ -434,7 +444,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ScrollViewSample/ScrollViewSample-Prefix.pch";
INFOPLIST_FILE = "ScrollViewSample/ScrollViewSample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand Down
Binary file not shown.
Expand Up @@ -10,13 +10,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m"
timestampString = "471368133.411753"
timestampString = "495658850.55322"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "-calculateMarginBetweenItems"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -26,13 +26,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m"
timestampString = "471368417.124136"
timestampString = "495658850.55322"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "101"
endingLineNumber = "101"
startingLineNumber = "118"
endingLineNumber = "118"
landmarkName = "-calculateMarginBetweenItems"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -42,13 +42,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m"
timestampString = "471368926.293709"
timestampString = "495658850.55322"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "99"
endingLineNumber = "99"
startingLineNumber = "116"
endingLineNumber = "116"
landmarkName = "-calculateMarginBetweenItems"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Expand Up @@ -8,6 +8,7 @@
* Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1
* Edit by WEIWEI CHEN 15-12-09: add comments on functions, remove scale when calculating margin, it seems that the behaviour in iOS 9 change the way of align views
* Edit by WEIWEI CHEN 16-05-17: fix removeItemAtIndex last index crash bug
* Edit by WEIWEI CHEN 16-09-15: add support to nib, just change the class on nib file to ASHorizontalScrollView
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand All @@ -29,28 +30,40 @@ - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_items = [NSMutableArray array];

//default item size is 80% of height
_uniformItemSize = CGSizeMake(frame.size.height*0.8, frame.size.height*0.8);

//default attributes
_leftMarginPx = kDefaultLeftMargin;
_miniMarginPxBetweenItems = kMinMarginBetweenItems;
_miniAppearPxOfLastItem = kMinWidthAppearOfLastItem;

//get default item margin
[self setItemsMarginOnce];

[self setShowsHorizontalScrollIndicator:NO];
[self setDecelerationRate:UIScrollViewDecelerationRateFast];

scrollViewdelegate = [[ASHorizontalScrollViewDelegate alloc] init];
self.delegate = scrollViewdelegate;
[self initView];
}
return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self initView];
}
return self;
}

- (void)initView {
_items = [NSMutableArray array];

//default item size is 80% of height
_uniformItemSize = CGSizeMake(self.frame.size.height*0.8, self.frame.size.height*0.8);

//default attributes
_leftMarginPx = kDefaultLeftMargin;
_miniMarginPxBetweenItems = kMinMarginBetweenItems;
_miniAppearPxOfLastItem = kMinWidthAppearOfLastItem;

//get default item margin
[self setItemsMarginOnce];

[self setShowsHorizontalScrollIndicator:NO];
[self setDecelerationRate:UIScrollViewDecelerationRateFast];

scrollViewdelegate = [[ASHorizontalScrollViewDelegate alloc] init];
self.delegate = scrollViewdelegate;
}

- (void)setFrame:(CGRect)frame
{
CGRect oldValue = self.frame;
Expand All @@ -67,7 +80,12 @@ - (void)setUniformItemSize:(CGSize)uniformItemSize
itemY = (self.frame.size.height-uniformItemSize.height)/2;
}


- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:[UIButton class]]) {
return true;
}
return false;
}

#pragma mark - add item
- (void)addItem:(UIView*)item
Expand Down
Expand Up @@ -5,7 +5,7 @@
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-2.
*
* Edit by WEIWEI CHEN 16-09-15: avoid cloeset index smaller than 0 when only one item showed in screen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
Expand All @@ -29,6 +29,9 @@ - (float)getClosestItemByX:(float)xPosition inScrollView:(ASHorizontalScrollView
{
//get current cloest item on the left side
int index = (int)((xPosition - scrollView.leftMarginPx)/(scrollView.itemsMargin+scrollView.uniformItemSize.width));
if (index < 0) {
index = 0;
}
UIView *item = [scrollView.items objectAtIndex:index];
//check if target position is over half of current left item, if so, move to next item
if (xPosition-item.frame.origin.x>item.frame.size.width/2) {
Expand Down
56 changes: 37 additions & 19 deletions Sources/ASHorizontalScrollView/ASHorizontalScrollView.m
Expand Up @@ -8,6 +8,7 @@
* Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1
* Edit by WEIWEI CHEN 15-12-09: add comments on functions, remove scale when calculating margin, it seems that the behaviour in iOS 9 change the way of align views
* Edit by WEIWEI CHEN 16-05-17: fix removeItemAtIndex last index crash bug
* Edit by WEIWEI CHEN 16-09-15: add support to nib, just change the class on nib file to ASHorizontalScrollView
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand All @@ -29,28 +30,40 @@ - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_items = [NSMutableArray array];

//default item size is 80% of height
_uniformItemSize = CGSizeMake(frame.size.height*0.8, frame.size.height*0.8);

//default attributes
_leftMarginPx = kDefaultLeftMargin;
_miniMarginPxBetweenItems = kMinMarginBetweenItems;
_miniAppearPxOfLastItem = kMinWidthAppearOfLastItem;

//get default item margin
[self setItemsMarginOnce];

[self setShowsHorizontalScrollIndicator:NO];
[self setDecelerationRate:UIScrollViewDecelerationRateFast];

scrollViewdelegate = [[ASHorizontalScrollViewDelegate alloc] init];
self.delegate = scrollViewdelegate;
[self initView];
}
return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self initView];
}
return self;
}

- (void)initView {
_items = [NSMutableArray array];

//default item size is 80% of height
_uniformItemSize = CGSizeMake(self.frame.size.height*0.8, self.frame.size.height*0.8);

//default attributes
_leftMarginPx = kDefaultLeftMargin;
_miniMarginPxBetweenItems = kMinMarginBetweenItems;
_miniAppearPxOfLastItem = kMinWidthAppearOfLastItem;

//get default item margin
[self setItemsMarginOnce];

[self setShowsHorizontalScrollIndicator:NO];
[self setDecelerationRate:UIScrollViewDecelerationRateFast];

scrollViewdelegate = [[ASHorizontalScrollViewDelegate alloc] init];
self.delegate = scrollViewdelegate;
}

- (void)setFrame:(CGRect)frame
{
CGRect oldValue = self.frame;
Expand All @@ -67,7 +80,12 @@ - (void)setUniformItemSize:(CGSize)uniformItemSize
itemY = (self.frame.size.height-uniformItemSize.height)/2;
}


- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:[UIButton class]]) {
return true;
}
return false;
}

#pragma mark - add item
- (void)addItem:(UIView*)item
Expand Down
Expand Up @@ -5,7 +5,7 @@
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-2.
*
* Edit by WEIWEI CHEN 16-09-15: avoid cloeset index smaller than 0 when only one item showed in screen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
Expand All @@ -29,6 +29,9 @@ - (float)getClosestItemByX:(float)xPosition inScrollView:(ASHorizontalScrollView
{
//get current cloest item on the left side
int index = (int)((xPosition - scrollView.leftMarginPx)/(scrollView.itemsMargin+scrollView.uniformItemSize.width));
if (index < 0) {
index = 0;
}
UIView *item = [scrollView.items objectAtIndex:index];
//check if target position is over half of current left item, if so, move to next item
if (xPosition-item.frame.origin.x>item.frame.size.width/2) {
Expand Down

0 comments on commit fa7f835

Please sign in to comment.