Skip to content

Commit

Permalink
Merge pull request #61 from mrackwitz/fix/38_stop_small_hit_area
Browse files Browse the repository at this point in the history
Fix #38: Ensure a min hit area for stop buttons
  • Loading branch information
mrackwitz committed Sep 3, 2014
2 parents 9359906 + 35110ce commit 70fbaaf
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
71EC368A1805BB7100C85C5B /* MRNavigationBarProgressViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71EC36891805BB7100C85C5B /* MRNavigationBarProgressViewController.m */; };
71EC368F1805BB7100C85C5B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 71EC368E1805BB7100C85C5B /* Images.xcassets */; };
71EC36BA1805D94500C85C5B /* MRProgressOverlayTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71EC36B91805D94500C85C5B /* MRProgressOverlayTableViewController.m */; };
71ECDA1C19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71ECDA1B19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.m */; };
71F50A3C181895D200FF4B8E /* MRProgressOverlayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71F50A3B181895D200FF4B8E /* MRProgressOverlayViewController.m */; };
D93A6441ABA44EEBB39D49F5 /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B9C56F06180F46F3898B5A94 /* libPods-Example.a */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -57,6 +58,8 @@
71EC368E1805BB7100C85C5B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
71EC36B81805D94500C85C5B /* MRProgressOverlayTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MRProgressOverlayTableViewController.h; sourceTree = "<group>"; };
71EC36B91805D94500C85C5B /* MRProgressOverlayTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRProgressOverlayTableViewController.m; sourceTree = "<group>"; };
71ECDA1A19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MRStopButtonMinHitAreaViewController.h; sourceTree = "<group>"; };
71ECDA1B19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRStopButtonMinHitAreaViewController.m; sourceTree = "<group>"; };
71F50A3A181895D200FF4B8E /* MRProgressOverlayViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MRProgressOverlayViewController.h; sourceTree = "<group>"; };
71F50A3B181895D200FF4B8E /* MRProgressOverlayViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRProgressOverlayViewController.m; sourceTree = "<group>"; };
B9C56F06180F46F3898B5A94 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -129,6 +132,8 @@
71F50A3B181895D200FF4B8E /* MRProgressOverlayViewController.m */,
71EC36B81805D94500C85C5B /* MRProgressOverlayTableViewController.h */,
71EC36B91805D94500C85C5B /* MRProgressOverlayTableViewController.m */,
71ECDA1A19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.h */,
71ECDA1B19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.m */,
71EC368E1805BB7100C85C5B /* Images.xcassets */,
71EC36771805BB7100C85C5B /* Supporting Files */,
);
Expand Down Expand Up @@ -259,6 +264,7 @@
71E898CF1814506B0035F290 /* MRActivityIndicatorViewController.m in Sources */,
71E898D2181451710035F290 /* MRColorPaletteViewController.m in Sources */,
71EC368A1805BB7100C85C5B /* MRNavigationBarProgressViewController.m in Sources */,
71ECDA1C19B5447A00F86877 /* MRStopButtonMinHitAreaViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
53 changes: 52 additions & 1 deletion Example/Base.lproj/Main_iPhone.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="rS3-R9-Ivy">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="rS3-R9-Ivy">
<dependencies>
<deployment defaultVersion="1792" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
Expand Down Expand Up @@ -211,6 +211,26 @@
<segue destination="Stt-8f-Dyi" kind="push" id="mjh-SY-MPX"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="aTg-aZ-Brj" style="IBUITableViewCellStyleDefault" id="zgy-0j-HEG">
<rect key="frame" x="0.0" y="460" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="zgy-0j-HEG" id="fAd-no-pgk">
<rect key="frame" x="0.0" y="0.0" width="287" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="MRStopButton Min Hit Area" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="aTg-aZ-Brj">
<rect key="frame" x="15" y="0.0" width="270" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="HXa-es-5ki" kind="push" id="55r-vp-waj"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand Down Expand Up @@ -1093,6 +1113,37 @@
</objects>
<point key="canvasLocation" x="944" y="3426"/>
</scene>
<!--Stop Button Min Hit Area View Controller - MRStopButton Min Hit Area-->
<scene sceneID="Xri-ce-hdT">
<objects>
<viewController id="HXa-es-5ki" customClass="MRStopButtonMinHitAreaViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="dYs-AD-fFw">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" id="R18-jY-YyD" customClass="MRActivityIndicatorView">
<rect key="frame" x="138" y="100" width="44" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<view contentMode="scaleToFill" id="1gs-UP-mJB" customClass="MRCircularProgressView">
<rect key="frame" x="127" y="200" width="66" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" title="MRStopButton Min Hit Area" id="iMl-wQ-Nkl"/>
<connections>
<outlet property="activityIndicatorView" destination="R18-jY-YyD" id="zd6-Vw-qme"/>
<outlet property="circularProgressView" destination="1gs-UP-mJB" id="CNl-tC-KCx"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="R0Y-m5-e4H" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="944" y="4786"/>
</scene>
</scenes>
<resources>
<image name="aquarium-fish1.jpg" width="1600" height="1200"/>
Expand Down
13 changes: 13 additions & 0 deletions Example/MRStopButtonMinHitAreaViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MRStopButtonMinHitAreaViewController.h
// Example
//
// Created by Marius Rackwitz on 02/09/14.
// Copyright (c) 2014 Marius Rackwitz. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MRStopButtonMinHitAreaViewController : UIViewController

@end
37 changes: 37 additions & 0 deletions Example/MRStopButtonMinHitAreaViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// MRStopButtonMinHitAreaViewController.m
// Example
//
// Created by Marius Rackwitz on 02/09/14.
// Copyright (c) 2014 Marius Rackwitz. All rights reserved.
//

#import "MRStopButtonMinHitAreaViewController.h"
#import <MRProgress/MRProgress.h>


@interface MRStopButtonMinHitAreaViewController ()

@property (weak, nonatomic) IBOutlet MRActivityIndicatorView *activityIndicatorView;
@property (weak, nonatomic) IBOutlet MRCircularProgressView *circularProgressView;

@end


@implementation MRStopButtonMinHitAreaViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.activityIndicatorView.mayStop = YES;
self.circularProgressView.mayStop = YES;

[self.activityIndicatorView.stopButton addTarget:self action:@selector(onStop:) forControlEvents:UIControlEventTouchUpInside];
[self.circularProgressView.stopButton addTarget:self action:@selector(onStop:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)onStop:(UIButton *)button {
NSLog(@"Did triggered.");
}

@end
14 changes: 14 additions & 0 deletions src/Components/MRStopButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#import "MRProgressHelper.h"


static CGFloat const MRStopButtonMinSize = 44.0;


@interface MRStopButton ()

@property (nonatomic, weak, readwrite) CAShapeLayer *shapeLayer;
Expand Down Expand Up @@ -62,6 +65,17 @@ - (CGRect)frameThatFits:(CGRect)parentBounds {
sizeValue * insetSizeRatio);
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
if (self.frame.size.width >= MRStopButtonMinSize || self.frame.size.height >= MRStopButtonMinSize) {
return [super pointInside:point withEvent:event];
} else {
CGFloat maxOffsetX = MAX(0, (MRStopButtonMinSize - self.frame.size.width) / 2.0);
CGFloat maxOffsetY = MAX(0, (MRStopButtonMinSize - self.frame.size.height) / 2.0);
CGRect hitRect = CGRectInset(self.bounds, -maxOffsetX, -maxOffsetY);
return CGRectContainsPoint(hitRect, point);
}
}

- (void)layoutSubviews {
[super layoutSubviews];

Expand Down

0 comments on commit 70fbaaf

Please sign in to comment.