Skip to content

Commit

Permalink
Adapt iOS SDK 9.0
Browse files Browse the repository at this point in the history
Add comments on functions, remove scale when calculating margin, it
seems that the behaviour in iOS 9 change the way of align views
  • Loading branch information
terenceLuffy committed Dec 9, 2015
1 parent f5a0490 commit affc7e3
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 120 deletions.
17 changes: 6 additions & 11 deletions ScrollViewSample/ScrollViewSample.xcodeproj/project.pbxproj
Expand Up @@ -221,7 +221,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = SA;
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0710;
ORGANIZATIONNAME = Zuse;
TargetAttributes = {
7402EE06193BB82D00B1C37D = {
Expand Down Expand Up @@ -356,6 +356,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -419,6 +420,7 @@
GCC_PREFIX_HEADER = "ScrollViewSample/ScrollViewSample-Prefix.pch";
INFOPLIST_FILE = "ScrollViewSample/ScrollViewSample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -433,6 +435,7 @@
GCC_PREFIX_HEADER = "ScrollViewSample/ScrollViewSample-Prefix.pch";
INFOPLIST_FILE = "ScrollViewSample/ScrollViewSample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -442,18 +445,14 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ScrollViewSample.app/ScrollViewSample";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
"$(DEVELOPER_FRAMEWORKS_DIR)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ScrollViewSample/ScrollViewSample-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = "ScrollViewSampleTests/ScrollViewSampleTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand All @@ -464,14 +463,10 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ScrollViewSample.app/ScrollViewSample";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
"$(DEVELOPER_FRAMEWORKS_DIR)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ScrollViewSample/ScrollViewSample-Prefix.pch";
INFOPLIST_FILE = "ScrollViewSampleTests/ScrollViewSampleTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand Down
Binary file not shown.
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m"
timestampString = "471368133.411753"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
landmarkName = "-calculateMarginBetweenItems"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m"
timestampString = "471368417.124136"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "101"
endingLineNumber = "101"
landmarkName = "-calculateMarginBetweenItems"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m"
timestampString = "471368926.293709"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "99"
endingLineNumber = "99"
landmarkName = "-calculateMarginBetweenItems"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:ScrollViewSample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -86,10 +89,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
@@ -1,7 +1,13 @@
/* ---------------------------------------------------------
* ASHorizontalScrollView.h
* The MIT License (MIT)
* Copyright (C) 2014 WEIWEI CHEN
* Copyright (C) 2014-2015 WEIWEI CHEN
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-1.
* 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
*
*
* 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 @@ -21,39 +27,67 @@
ASHorizontalScrollViewDelegate *scrollViewdelegate;
}

//an array which refer to all added items
/// an array which refer to all added items
@property (strong, nonatomic, readonly) NSMutableArray *items;

//the uniform size of all added items, please set it before adding any items, otherwise, default size will be applied
/// the uniform size of all added items, please set it before adding any items, otherwise, default size will be applied
@property (nonatomic)CGSize uniformItemSize;

//store the current items' margin
/// store the current items' margin
@property (nonatomic, readonly)int itemsMargin;

//the margin between left border and first item
/// the margin between left border and first item
@property (nonatomic)float leftMarginPx;

//the mini margin between items, it is the seed to calculate the actual margin which is not less than
@property (nonatomic)float miniMarginPxBetweenItems;

//the mini width appear for last item of current screen, set it 0 if you don't want any part of the last item appear on the right
/// the mini width appear for last item of current screen, set it 0 if you don't want any part of the last item appear on the right
@property (nonatomic)float miniAppearPxOfLastItem;

//add new item into scroll view
/**
This add a new item into the scrollview
- parameter item: the item you would like to add, it must not be nil.
*/
- (void) addItem:(UIView*)item;

//add items into scroll view
/**
This add multi new items into the scrollview
- parameter items: the items in array you would like to add, it must not be nil.
*/
- (void) addItems:(NSArray*)items;

//remove item from scroll view with that specified item
/**
It removes the specified item from scrollview
- parameter item: the item you would like to remove.
- returns: true if removing successfully.
*/
- (BOOL) removeItem:(UIView*)item;

//remove item from scroll view with index in the array
/**
It removes the specified item at index from scrollview
- parameter index: the index of item you would like to remove.
- returns: true if removing successfully.
*/
- (BOOL) removeItemAtIndex:(NSInteger)index;

//remove all items
/**
It removes all items from scrollview
- returns: true if removing successfully.
*/
- (BOOL) removeAllItems;

//calculate items' margin, this must be called after setting any size or margin properties
/**
It re-calculate the item margin to fit in current view frame
- note: This must be called after changing any size or margin property of this class to get acurrate margin
- seealso: calculateMarginBetweenItems
*/
- (void) setItemsMarginOnce;
@end
@@ -1,10 +1,20 @@
//
// ASHorizontalScrollView.m
// ScrollViewSample
//
// Created by Vivien on 2014-06-01.
// Copyright (c) 2014 Zuse. All rights reserved.
//
/* ---------------------------------------------------------
* ASHorizontalScrollView.m
* The MIT License (MIT)
* Copyright (C) 2014-2015 WEIWEI CHEN
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-1.
* 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
*
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* -------------------------------------------------------*/

#import "ASHorizontalScrollView.h"

Expand Down Expand Up @@ -81,14 +91,14 @@ - (void)addItems:(NSArray *)items
}
}

//calculate the exact margin between items
/// Calculate the exact margin between items
- (int)calculateMarginBetweenItems
{
CGFloat scale = [UIScreen mainScreen].scale;
// CGFloat scale = [UIScreen mainScreen].scale;
//calculate how many items listed on current screen except the last half appearance one
int numberOfItemForCurrentWidth = floorf((self.frame.size.width*scale-self.leftMarginPx-self.miniAppearPxOfLastItem)/(_uniformItemSize.width+self.miniMarginPxBetweenItems));
int numberOfItemForCurrentWidth = floorf((self.frame.size.width-self.leftMarginPx-self.miniAppearPxOfLastItem)/(_uniformItemSize.width+self.miniMarginPxBetweenItems));

return round((self.frame.size.width*scale-self.leftMarginPx-self.miniAppearPxOfLastItem)/numberOfItemForCurrentWidth - _uniformItemSize.width);
return round((self.frame.size.width-self.leftMarginPx-self.miniAppearPxOfLastItem)/numberOfItemForCurrentWidth - _uniformItemSize.width);
}

- (void)setItemsMarginOnce
Expand All @@ -97,7 +107,6 @@ - (void)setItemsMarginOnce
}

#pragma mark - remove item

- (BOOL) removeAllItems
{
for (long i = self.items.count - 1; i >= 0; i--) {
Expand All @@ -110,7 +119,6 @@ - (BOOL) removeAllItems
return true;
}

//return whether removing action is success
- (BOOL)removeItem:(UIView *)item
{
NSInteger index = [self.items indexOfObject:item];
Expand All @@ -136,7 +144,7 @@ - (BOOL)removeItemAtIndex:(NSInteger)index
return true;
}

//refresh all subviews for changing size of current frame
/// Refresh all subviews for changing size of current frame
- (void) refreshSubView
{
[self setItemsMarginOnce];
Expand Down
@@ -1,7 +1,11 @@
/* ---------------------------------------------------------
* ASHorizontalScrollViewDelegate.h
* The MIT License (MIT)
* Copyright (C) 2014 WEIWEI CHEN
* Copyright (C) 2014-2015 WEIWEI CHEN
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-2.
*
*
* 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 Down
@@ -1,10 +1,18 @@
//
// ASHorizontalScrollViewDelegate.m
// ScrollViewSample
//
// Created by Vivien on 2014-06-02.
// Copyright (c) 2014 Zuse. All rights reserved.
//
/* ---------------------------------------------------------
* ASHorizontalScrollViewDelegate.m
* The MIT License (MIT)
* Copyright (C) 2014-2015 WEIWEI CHEN
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-2.
*
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* -------------------------------------------------------*/

#import "ASHorizontalScrollViewDelegate.h"
#import "ASHorizontalScrollView.h"
Expand Down
@@ -1,5 +1,5 @@
ASHorizontalScrollView
Copyright (c) 2014 WEIWEI CHEN
Copyright (c) 2014-2015 WEIWEI CHEN

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 Down

0 comments on commit affc7e3

Please sign in to comment.