Skip to content

Commit

Permalink
Merge pull request #10 from LeoMobileDeveloper/develop
Browse files Browse the repository at this point in the history
v 0.4.0
  • Loading branch information
LeoMobileDeveloper authored Nov 18, 2018
2 parents 85aad80 + 517cdaa commit 0bed21b
Show file tree
Hide file tree
Showing 24 changed files with 571 additions and 62 deletions.
66 changes: 57 additions & 9 deletions Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,55 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kmx-NE-WpS">
<rect key="frame" x="158" y="318" width="59" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Click Me"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kmx-NE-WpS">
<rect key="frame" x="148.5" y="298.5" width="78" height="30"/>
<state key="normal" title="Core Demo"/>
<connections>
<segue destination="UfB-hx-yKX" kind="show" id="rwT-RC-hCA"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5Qj-J6-yeM">
<rect key="frame" x="121.5" y="338.5" width="132" height="30"/>
<state key="normal" title="UIResponser Demo"/>
<connections>
<segue destination="qXn-Nz-YLY" kind="show" id="NgL-qB-NZJ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="5Qj-J6-yeM" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="20" id="4Xx-Ce-r87"/>
<constraint firstItem="5Qj-J6-yeM" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="98x-RA-7Qa"/>
<constraint firstItem="kmx-NE-WpS" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="qpU-9k-8wE"/>
<constraint firstItem="kmx-NE-WpS" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="-20" id="x16-jO-7Vw"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="CQU-Sg-UIy"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="719" y="-564"/>
</scene>
<!--Demo-->
<!--UIResponser Demo-->
<scene sceneID="st6-5p-095">
<objects>
<tableViewController id="qXn-Nz-YLY" customClass="DemoTableViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="rcc-Yl-Ibx">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="dataSource" destination="qXn-Nz-YLY" id="NAN-bd-r0Z"/>
<outlet property="delegate" destination="qXn-Nz-YLY" id="2ji-vv-VPC"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="UIResponser Demo" id="eUW-sA-z4b"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="9Oz-M2-GIa" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1666" y="-343"/>
</scene>
<!--Core-->
<scene sceneID="8Zq-hH-jqD">
<objects>
<viewController id="UfB-hx-yKX" customClass="DemoViewController" sceneMemberID="viewController">
Expand All @@ -58,7 +89,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DAf-9g-R9z">
<rect key="frame" x="115.5" y="274.5" width="144" height="30"/>
<rect key="frame" x="115.5" y="280.5" width="144" height="30"/>
<state key="normal" title="Dispatch Notification"/>
<connections>
<action selector="dispatchNotification:" destination="UfB-hx-yKX" eventType="touchUpInside" id="XZN-wZ-wqm"/>
Expand All @@ -71,22 +102,39 @@
<action selector="dispatchString:" destination="UfB-hx-yKX" eventType="touchUpInside" id="8D8-wz-two"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Click and view log " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bJe-KU-79l">
<rect key="frame" x="116.5" y="84" width="142" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Og7-Wh-LQt">
<rect key="frame" x="135" y="394" width="105" height="30"/>
<state key="normal" title="Dispatch JSON"/>
<connections>
<action selector="dispatchJson:" destination="UfB-hx-yKX" eventType="touchUpInside" id="WCe-sY-ZWU"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="MXl-SO-nrb" firstAttribute="centerY" secondItem="gBg-dr-YJh" secondAttribute="centerY" id="0ee-IM-VqN"/>
<constraint firstItem="Gzk-EX-vLV" firstAttribute="top" secondItem="MXl-SO-nrb" secondAttribute="bottom" constant="7.5" id="CxM-iL-nxJ"/>
<constraint firstItem="MXl-SO-nrb" firstAttribute="centerX" secondItem="gBg-dr-YJh" secondAttribute="centerX" id="DQZ-jE-IBh"/>
<constraint firstItem="DAf-9g-R9z" firstAttribute="centerX" secondItem="MXl-SO-nrb" secondAttribute="centerX" id="Dz4-ce-Yux"/>
<constraint firstItem="bJe-KU-79l" firstAttribute="top" secondItem="eOf-31-Oau" secondAttribute="bottom" constant="20" id="KJx-M1-fns"/>
<constraint firstItem="bJe-KU-79l" firstAttribute="centerX" secondItem="gBg-dr-YJh" secondAttribute="centerX" id="RuX-sw-sfz"/>
<constraint firstItem="Og7-Wh-LQt" firstAttribute="top" secondItem="Gzk-EX-vLV" secondAttribute="bottom" constant="8" id="VDX-q6-HJR"/>
<constraint firstItem="Gzk-EX-vLV" firstAttribute="centerX" secondItem="MXl-SO-nrb" secondAttribute="centerX" id="fN7-kG-dEe"/>
<constraint firstItem="MXl-SO-nrb" firstAttribute="top" secondItem="DAf-9g-R9z" secondAttribute="bottom" constant="14" id="uup-6p-Jot"/>
<constraint firstItem="Og7-Wh-LQt" firstAttribute="centerX" secondItem="Gzk-EX-vLV" secondAttribute="centerX" id="hFn-h7-v7J"/>
<constraint firstItem="MXl-SO-nrb" firstAttribute="top" secondItem="DAf-9g-R9z" secondAttribute="bottom" constant="8" id="uup-6p-Jot"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Demo" id="4Hn-Xo-L8m"/>
<navigationItem key="navigationItem" title="Core" id="4Hn-Xo-L8m"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8QO-bK-JYK" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1476" y="-564"/>
<point key="canvasLocation" x="1711" y="-1065"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Rtc-PG-pnE">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions Demo/DemoViewController.m → Demo/Core/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ - (void)viewDidLoad {
[QTSubName(self, @"ButtonClickedEvent") next:^(NSString *event) {
NSLog(@"%@",@"Receive String Event");
}];
[QTSubJSON(self, @"EventKey") next:^(QTJsonEvent *event) {
NSLog(@"Receive Json Event: %@",event.data);
}];
}


Expand All @@ -54,6 +57,12 @@ - (IBAction)dispatchString:(id)sender {
[[QTEventBus shared] dispatch:@"ButtonClickedEvent"];
}

- (IBAction)dispatchJson:(id)sender {
QTJsonEvent * event = [QTJsonEvent eventWithId:@"EventKey"
jsonObject:@{@"Author" : @"LeoMobileDeveloper"}];
[[QTEventBus shared] dispatch:event];
}

- (void)dealloc{
NSLog(@"Dealloc: %@",NSStringFromClass(self.class));
}
Expand Down
28 changes: 28 additions & 0 deletions Demo/UIResponser/DemoTableViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// DemoTableViewCell.h
// Demo
//
// Created by Leo on 2018/11/18.
// Copyright © 2018 Leo Huang. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "QTEventBus+UIKit.h"

extern NSString * const Button1ClickedEvent; // 不带数据的Event

// 携带数据的Event
@interface Button2ClickEvent : NSObject<QTEvent>

@property (strong, nonatomic) UITableViewCell * cell;

@end

NS_ASSUME_NONNULL_BEGIN

@interface DemoTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *indexLabel;

@end

NS_ASSUME_NONNULL_END
40 changes: 40 additions & 0 deletions Demo/UIResponser/DemoTableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// DemoTableViewCell.m
// Demo
//
// Created by Leo on 2018/11/18.
// Copyright © 2018 Leo Huang. All rights reserved.
//

#import "DemoTableViewCell.h"

NSString * const Button1ClickedEvent = @"Button1ClickedEvent"; // 不带数据的Event

@implementation Button2ClickEvent

@end

@implementation DemoTableViewCell

- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

- (IBAction)button1Clicked:(id)sender {
[self.eventDispatcher dispatch:Button1ClickedEvent];
}

- (IBAction)button2Clicked:(id)sender {
Button2ClickEvent * event = [[Button2ClickEvent alloc] init];
event.cell = self;
[self.eventDispatcher dispatch:event];
}

@end
57 changes: 57 additions & 0 deletions Demo/UIResponser/DemoTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="DemoTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5Lf-zH-Cg9">
<rect key="frame" x="63" y="7" width="57" height="30"/>
<state key="normal" title="Button 1"/>
<connections>
<action selector="button1Clicked:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="A94-qh-4ei"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="642-Gh-KSM">
<rect key="frame" x="249" y="7" width="55" height="30"/>
<state key="normal" title="Button2"/>
<connections>
<action selector="button2Clicked:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="B5o-9o-hmm"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sZ6-AK-gcQ">
<rect key="frame" x="8" y="11.5" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="5Lf-zH-Cg9" firstAttribute="leading" secondItem="sZ6-AK-gcQ" secondAttribute="trailing" constant="13" id="EAw-hf-6ce"/>
<constraint firstItem="5Lf-zH-Cg9" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="Urp-xt-Zrj"/>
<constraint firstItem="642-Gh-KSM" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="YqV-ui-BIZ"/>
<constraint firstAttribute="trailing" secondItem="642-Gh-KSM" secondAttribute="trailing" constant="16" id="e5P-rn-6j4"/>
<constraint firstItem="sZ6-AK-gcQ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="8" id="eAR-Ju-iBM"/>
<constraint firstItem="sZ6-AK-gcQ" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="qeB-K6-UBv"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="indexLabel" destination="sZ6-AK-gcQ" id="4Zb-ie-cYd"/>
</connections>
<point key="canvasLocation" x="50" y="97"/>
</tableViewCell>
</objects>
</document>
17 changes: 17 additions & 0 deletions Demo/UIResponser/DemoTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// DemoTableViewController.h
// Demo
//
// Created by Leo on 2018/11/18.
// Copyright © 2018 Leo Huang. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface DemoTableViewController : UITableViewController

@end

NS_ASSUME_NONNULL_END
60 changes: 60 additions & 0 deletions Demo/UIResponser/DemoTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// DemoTableViewController.m
// Demo
//
// Created by Leo on 2018/11/18.
// Copyright © 2018 Leo Huang. All rights reserved.
//

#import "DemoTableViewController.h"
#import "DemoTableViewCell.h"

@interface DemoTableViewController ()

@end

@implementation DemoTableViewController

- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"DemoTableViewCell" bundle:nil]
forCellReuseIdentifier:@"cell"];
//弱持有Self,因为self持有EventBus,EventBus持有block
__weak typeof(self) weakSelf = self;

//Cell中Button1点击,采用String来唯一区分
[[self subscribeName:Button1ClickedEvent on:self.eventDispatcher]
next:^(NSString *event) {
NSLog(@"Button 1 clicked");
}];

//Cell中Button2点击,采用类来区分
[[self subscribe:Button2ClickEvent.class on:self.eventDispatcher]
next:^(Button2ClickEvent * event) {
NSIndexPath * indexPath = [weakSelf.tableView indexPathForCell:event.cell];
NSLog(@"Button 2 in cell %ld clicked",(long)indexPath.row);
}];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DemoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.indexLabel.text = @(indexPath.row).stringValue;
return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50.0;
}


@end
8 changes: 7 additions & 1 deletion QTEventBus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'QTEventBus'
s.version = '0.3.0'
s.version = '0.4.0'
s.summary = '优雅的处理全局事件'
s.description = <<-DESC
优雅的处理全局事件,类型安全,支持同步/异步发送,同步/异步监听
Expand All @@ -22,4 +22,10 @@ Pod::Spec.new do |s|
app.framework = 'UIKit'
app.dependency 'QTEventBus/Core'
end

s.subspec 'UIKit' do |app|
app.source_files = 'Sources/UIKit/*.{h,m}'
app.framework = 'UIKit'
app.dependency 'QTEventBus/Core'
end
end
Loading

0 comments on commit 0bed21b

Please sign in to comment.