Skip to content

Commit

Permalink
Device orientation delegate method and podfile update (#66)
Browse files Browse the repository at this point in the history
* Update podfile to latest cocoapods format.
Updated .gitignore to ignore example/pod changes

* Removing cached files inside the example/pod folder to ignore Example/Pods/* files moving forward.

* Podfile update (#1)

* Update podfile to latest cocoapods format.
Updated .gitignore to ignore example/pod changes

* Removing cached files inside the example/pod folder to ignore Example/Pods/* files moving forward.

* Fixes the following warning: "Assigning to 'id<CAAnimationDelegate> _Nullable' from incompatible type 'DCPathButton *const __strong'" (#2)

* - Added DCPathButton delegate method for device orientation changes.
- Updated example project to show use of new delegate method on device orientation change.
  • Loading branch information
kevnm67 authored and Tangdixi committed Jul 12, 2017
1 parent 0810610 commit 8da1ee4
Show file tree
Hide file tree
Showing 37 changed files with 337 additions and 1,745 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ profile
*.moved-aside
DerivedData
.idea/

Example/Pods
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
language: objective-c
xcode_workspace: Example/Example.xcworkspace
xcode_scheme: Example
osx_image: xcode8.3
podfile: Example/Podfile
xcode_scheme: Example
xcode_workspace: Example/Example.xcworkspace
before_install:
- brew update
- brew outdated xctool || brew upgrade xctool
17 changes: 17 additions & 0 deletions DCPathButton/Classes/DCPathButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

@class DCPathButton;

/*!
* The device orientation.
*/
typedef NS_ENUM(NSInteger, DCPathButtonOrientation) {
DCPathButtonOrientationUnknown,
DCPathButtonOrientationPortrait,
DCPathButtonOrientationLandscape
};

/*!
* The direction of a `DCPathButton` object's bloom animation.
*/
Expand Down Expand Up @@ -93,6 +102,14 @@ typedef NS_ENUM(NSUInteger, kDCPathButtonBloomDirection) {
*/
- (void)didDismissDCPathButtonItems:(DCPathButton *)dcPathButton;

/*!
* Tells the delegate the device orientation changed. Use this method to change the path buttons center.
*
* @param dcPathButton A `DCPathButton` object who received a device orientation changed notification.
* @param orientation The updated device orientation.
*/
- (void)pathButton:(DCPathButton *)dcPathButton didUpdateOrientation:(DCPathButtonOrientation)orientation;

@end

@interface DCPathButton : UIView <UIGestureRecognizerDelegate>
Expand Down
47 changes: 47 additions & 0 deletions DCPathButton/Classes/DCPathButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ - (instancetype)initWithButtonFrame:(CGRect)centerButtonFrame

_basicDuration = 0.3f;

[self configureDeviceOrientationObserver];

}
return self;
}

- (void)dealloc {
[self cleanUpOrientationObservers];
}

- (void)configureViewsLayoutWithButtonSize:(CGSize)centerButtonSize {
// Init some property only once
//
Expand Down Expand Up @@ -256,6 +262,47 @@ - (BOOL)isBloom {
return _bloom;
}

#pragma mark - Orientation Changes

- (void)configureDeviceOrientationObserver {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

// Register for orientation change notifications.
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateDCPathButtonForOrientationChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}

- (void)updateDCPathButtonForOrientationChangeNotification:(NSNotification *)notification {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;

if ([self.delegate respondsToSelector:@selector(pathButton:didUpdateOrientation:)]) {
DCPathButtonOrientation dcPathOrientation = [self dcPathOrientationFromOrientation:orientation];

[self.delegate pathButton:self didUpdateOrientation:dcPathOrientation];
}
}

- (DCPathButtonOrientation)dcPathOrientationFromOrientation:(UIDeviceOrientation)orientation {
if (orientation == UIDeviceOrientationUnknown) {
return DCPathButtonOrientationUnknown;
}

BOOL isPortrait = UIDeviceOrientationIsPortrait(orientation);

return (isPortrait ? DCPathButtonOrientationPortrait : DCPathButtonOrientationLandscape);
}

- (void)cleanUpOrientationObservers {
// Stop generating orientation notifications.
//
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Center Button Delegate

- (void)centerButtonTapped {
Expand Down
Loading

0 comments on commit 8da1ee4

Please sign in to comment.