[ios] Updated circular progress.

This commit is contained in:
Ilya Grechuhin 2015-10-20 16:09:18 +03:00 committed by v.mikhaylenko
parent 7a27ba1975
commit 8895fa504a
10 changed files with 137 additions and 60 deletions

View file

@ -12,9 +12,14 @@
@property (nonatomic) CGFloat progress;
@property (nonatomic) BOOL failed;
@property (nonatomic) BOOL selected;
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;
- (nonnull instancetype)init __attribute__((unavailable("init is not available")));
- (nonnull instancetype)initWithParentView:(nonnull UIView *)parentView delegate:(nonnull id <MWMCircularProgressDelegate>)delegate;
- (void)reset;
- (void)startSpinner;
- (void)stopSpinner;
@end

View file

@ -33,6 +33,23 @@
self.nextProgressToAnimate = nil;
}
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state
{
[self.button setImage:image forState:state];
}
#pragma mark - Spinner
- (void)startSpinner
{
[self.rootView startSpinner];
}
- (void)stopSpinner
{
[self.rootView stopSpinner];
}
#pragma mark - Animation
- (void)animationDidStop:(CABasicAnimation *)anim finished:(BOOL)flag
@ -80,4 +97,14 @@
return self.button.selected;
}
- (void)setSelected:(BOOL)selected
{
self.button.selected = selected;
}
- (BOOL)selected
{
return self.button.selected;
}
@end

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MWMCircularProgress">
@ -18,6 +18,7 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" adjustsImageWhenHighlighted="NO" adjustsImageWhenDisabled="NO" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="viF-Ee-7h0">
<rect key="frame" x="-6" y="-6" width="44" height="44"/>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<state key="normal" image="ic_stop_spinner">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
@ -27,18 +28,28 @@
<action selector="buttonTouchUpInside:" destination="-1" eventType="touchUpInside" id="aPG-4e-uSw"/>
</connections>
</button>
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="aMt-XV-9UK" userLabel="Spinner">
<rect key="frame" x="0.0" y="0.0" width="32" height="32"/>
<animations/>
</imageView>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="viF-Ee-7h0" firstAttribute="top" secondItem="2DE-Qh-89K" secondAttribute="top" constant="-6" id="3gS-24-Olj"/>
<constraint firstItem="aMt-XV-9UK" firstAttribute="leading" secondItem="2DE-Qh-89K" secondAttribute="leading" id="JK6-QX-JcI"/>
<constraint firstAttribute="bottom" secondItem="aMt-XV-9UK" secondAttribute="bottom" id="VFI-Yh-q1q"/>
<constraint firstAttribute="trailing" secondItem="viF-Ee-7h0" secondAttribute="trailing" constant="-6" id="fQT-G3-rJF"/>
<constraint firstItem="aMt-XV-9UK" firstAttribute="top" secondItem="2DE-Qh-89K" secondAttribute="top" id="fbs-bw-DIs"/>
<constraint firstAttribute="bottom" secondItem="viF-Ee-7h0" secondAttribute="bottom" constant="-6" id="j4s-7V-lg9"/>
<constraint firstAttribute="trailing" secondItem="aMt-XV-9UK" secondAttribute="trailing" id="k01-wU-25n"/>
<constraint firstItem="viF-Ee-7h0" firstAttribute="leading" secondItem="2DE-Qh-89K" secondAttribute="leading" constant="-6" id="sHS-iu-Url"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="owner" destination="-1" id="0n7-PI-5tO"/>
<outlet property="spinner" destination="aMt-XV-9UK" id="bmp-bV-h3C"/>
</connections>
</view>
</objects>

View file

@ -11,5 +11,7 @@
- (void)refreshProgress;
- (void)updatePath:(CGFloat)progress;
- (void)startSpinner;
- (void)stopSpinner;
@end

View file

@ -16,6 +16,7 @@ static inline CGFloat angleWithProgress(CGFloat progress)
@property (nonatomic) CAShapeLayer * progressLayer;
@property (weak, nonatomic) IBOutlet MWMCircularProgress * owner;
@property (weak, nonatomic) IBOutlet UIImageView * spinner;
@end
@ -50,6 +51,8 @@ static inline CGFloat angleWithProgress(CGFloat progress)
- (void)updatePath:(CGFloat)progress
{
if (progress > 0.0)
[self stopSpinner];
CGFloat const outerRadius = self.width / 2.0;
CGPoint const center = CGPointMake(outerRadius, outerRadius);
CGFloat const radius = outerRadius - kLineWidth;
@ -57,6 +60,32 @@ static inline CGFloat angleWithProgress(CGFloat progress)
self.progressLayer.path = path.CGPath;
}
#pragma mark - Spinner
- (void)startSpinner
{
if (!self.spinner.hidden)
return;
self.backgroundLayer.hidden = self.progressLayer.hidden = YES;
self.spinner.hidden = NO;
NSUInteger const animationImagesCount = 12;
NSMutableArray * animationImages = [NSMutableArray arrayWithCapacity:animationImagesCount];
for (NSUInteger i = 0; i < animationImagesCount; ++i)
animationImages[i] = [UIImage imageNamed:[NSString stringWithFormat:@"Spinner_%@", @(i+1)]];
self.spinner.animationImages = animationImages;
[self.spinner startAnimating];
}
- (void)stopSpinner
{
if (self.spinner.hidden)
return;
self.backgroundLayer.hidden = self.progressLayer.hidden = NO;
self.spinner.hidden = YES;
[self.spinner.layer removeAllAnimations];
}
#pragma mark - Animation
- (void)animateFromValue:(CGFloat)fromValue toValue:(CGFloat)toValue

View file

@ -224,29 +224,29 @@
- (IBAction)routePreviewChange:(MWMRouteTypeButton *)sender
{
if (sender.selected)
return;
sender.selected = YES;
self.activeRouteTypeButton = sender;
auto & f = GetFramework();
routing::RouterType type;
if ([sender isEqual:self.routePreview.pedestrian])
{
self.routePreview.vehicle.selected = NO;
type = routing::RouterType::Pedestrian;
}
else
{
self.routePreview.pedestrian.selected = NO;
type = routing::RouterType::Vehicle;
}
f.CloseRouting();
f.SetRouter(type);
f.SetLastUsedRouter(type);
if (!self.delegate.isPossibleToBuildRoute)
return;
[sender startAnimating];
[self.delegate buildRoute];
// if (sender.selected)
// return;
// sender.selected = YES;
// self.activeRouteTypeButton = sender;
// auto & f = GetFramework();
// routing::RouterType type;
// if ([sender isEqual:self.routePreview.pedestrian])
// {
// self.routePreview.vehicle.selected = NO;
// type = routing::RouterType::Pedestrian;
// }
// else
// {
// self.routePreview.pedestrian.selected = NO;
// type = routing::RouterType::Vehicle;
// }
// f.CloseRouting();
// f.SetRouter(type);
// f.SetLastUsedRouter(type);
// if (!self.delegate.isPossibleToBuildRoute)
// return;
// [sender startAnimating];
// [self.delegate buildRoute];
}
- (void)setRouteBuildingProgress:(CGFloat)progress
@ -324,19 +324,19 @@
- (void)setupActualRoute
{
switch (GetFramework().GetRouter())
{
case routing::RouterType::Pedestrian:
self.routePreview.pedestrian.selected = YES;
self.routePreview.vehicle.selected = NO;
self.activeRouteTypeButton = self.routePreview.pedestrian;
break;
case routing::RouterType::Vehicle:
self.routePreview.vehicle.selected = YES;
self.routePreview.pedestrian.selected = NO;
self.activeRouteTypeButton = self.routePreview.vehicle;
break;
}
// switch (GetFramework().GetRouter())
// {
// case routing::RouterType::Pedestrian:
// self.routePreview.pedestrian.selected = YES;
// self.routePreview.vehicle.selected = NO;
// self.activeRouteTypeButton = self.routePreview.pedestrian;
// break;
// case routing::RouterType::Vehicle:
// self.routePreview.vehicle.selected = YES;
// self.routePreview.pedestrian.selected = NO;
// self.activeRouteTypeButton = self.routePreview.vehicle;
// break;
// }
}
#pragma mark - Properties

View file

@ -14,8 +14,6 @@
@interface MWMRoutePreview : MWMNavigationView
@property (weak, nonatomic) IBOutlet MWMRouteTypeButton * pedestrian;
@property (weak, nonatomic) IBOutlet MWMRouteTypeButton * vehicle;
@property (weak, nonatomic, readonly) IBOutlet UIButton * extendButton;
@property (weak, nonatomic) id<MWMRoutePreviewDataSource> dataSource;
@property (weak, nonatomic) MWMNavigationDashboardManager * dashboardManager;

View file

@ -1,4 +1,5 @@
#import "Common.h"
#import "MWMCircularProgress.h"
#import "MWMNavigationDashboardEntity.h"
#import "MWMNavigationDashboardManager.h"
#import "MWMRoutePointCell.h"
@ -14,8 +15,10 @@ static NSDictionary * const kEtaAttributes = @{NSForegroundColorAttributeName :
static CGFloat const kBottomPanelHeight = 48.;
static CGFloat const kAdditionalHeight = 20.;
@interface MWMRoutePreview () <MWMRoutePointCellDelegate>
@interface MWMRoutePreview () <MWMRoutePointCellDelegate, MWMCircularProgressDelegate>
@property (weak, nonatomic) IBOutlet UIView * pedestrian;
@property (weak, nonatomic) IBOutlet UIView * vehicle;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * planningRouteViewHeight;
@property (weak, nonatomic, readwrite) IBOutlet UIButton * extendButton;
@property (weak, nonatomic) IBOutlet UIButton * goButton;
@ -32,6 +35,9 @@ static CGFloat const kAdditionalHeight = 20.;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * statusBoxHeight;
@property (nonatomic) UIImageView * movingCellImage;
@property (nonatomic) MWMCircularProgress * pedestrianProgressView;
@property (nonatomic) MWMCircularProgress * vehicleProgressView;
@end
@implementation MWMRoutePreview
@ -44,6 +50,15 @@ static CGFloat const kAdditionalHeight = 20.;
self.layer.rasterizationScale = UIScreen.mainScreen.scale;
[self.collectionView registerNib:[UINib nibWithNibName:[MWMRoutePointCell className] bundle:nil]
forCellWithReuseIdentifier:[MWMRoutePointCell className]];
self.pedestrianProgressView = [[MWMCircularProgress alloc] initWithParentView:self.pedestrian delegate:self];
[self.pedestrianProgressView setImage:[UIImage imageNamed:@"ic_drive_off"] forState:UIControlStateNormal];
[self.pedestrianProgressView setImage:[UIImage imageNamed:@"ic_drive_press"] forState:UIControlStateHighlighted];
[self.pedestrianProgressView setImage:[UIImage imageNamed:@"ic_drive_on"] forState:UIControlStateSelected];
self.vehicleProgressView = [[MWMCircularProgress alloc] initWithParentView:self.vehicle delegate:self];
[self.vehicleProgressView setImage:[UIImage imageNamed:@"ic_walk_off"] forState:UIControlStateNormal];
[self.vehicleProgressView setImage:[UIImage imageNamed:@"ic_walk_press"] forState:UIControlStateHighlighted];
[self.vehicleProgressView setImage:[UIImage imageNamed:@"ic_walk_on"] forState:UIControlStateSelected];
}
- (void)didMoveToSuperview
@ -172,6 +187,12 @@ static CGFloat const kAdditionalHeight = 20.;
[self.delegate routePreviewDidChangeFrame:self.frame];
}
#pragma mark - MWMCircularProgressDelegate
- (void)progressButtonPressed:(nonnull MWMCircularProgress *)progress
{
}
#pragma mark - Properties
- (CGRect)defaultFrame

View file

@ -187,28 +187,18 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="oQc-l8-sZH" userLabel="Buttons Box">
<rect key="frame" x="8" y="0.0" width="96" height="48"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cZF-Ha-2tB" customClass="MWMRouteTypeButton">
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cZF-Ha-2tB">
<rect key="frame" x="0.0" y="0.0" width="48" height="48"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="icon" value="ic_drive_off"/>
<userDefinedRuntimeAttribute type="image" keyPath="highlightedIcon" value="ic_type_drive_off_press"/>
<userDefinedRuntimeAttribute type="image" keyPath="selectedIcon" value="ic_drive_on"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="routePreviewChange:" destination="-1" eventType="touchUpInside" id="OZw-Td-RZg"/>
</connections>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6D3-QF-6wm" customClass="MWMRouteTypeButton">
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6D3-QF-6wm">
<rect key="frame" x="48" y="0.0" width="48" height="48"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="icon" value="ic_walk_off"/>
<userDefinedRuntimeAttribute type="image" keyPath="highlightedIcon" value="ic_type_walk_off_press"/>
<userDefinedRuntimeAttribute type="image" keyPath="selectedIcon" value="ic_walk_on"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="routePreviewChange:" destination="-1" eventType="touchUpInside" id="rGh-pI-yHL"/>
</connections>
@ -286,12 +276,6 @@
</objects>
<resources>
<image name="ic_arrow_up_and_down" width="9" height="9"/>
<image name="ic_drive_off" width="40" height="40"/>
<image name="ic_drive_on" width="40" height="40"/>
<image name="ic_nav_bar_back" width="44" height="44"/>
<image name="ic_type_drive_off_press" width="40" height="40"/>
<image name="ic_type_walk_off_press" width="41" height="40"/>
<image name="ic_walk_off" width="41" height="40"/>
<image name="ic_walk_on" width="41" height="40"/>
</resources>
</document>

View file

@ -11,7 +11,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="223"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="jfp-wb-Z7G" id="kUu-ao-FYN">
<rect key="frame" x="0.0" y="0.0" width="320" height="222.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="223"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_bookmark" translatesAutoresizingMaskIntoConstraints="NO" id="NJ3-lK-ziZ" userLabel="Bookmark icon">