Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Finder generated
.DS_Store

## Vim's swap files
*.swp

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots

#Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
11 changes: 8 additions & 3 deletions TYPagerControllerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
B072EC0D1F1E37B100736A2E /* TYPagerView.m in Sources */ = {isa = PBXBuildFile; fileRef = B072EC041F1E37B100736A2E /* TYPagerView.m */; };
B072EC0E1F1E37B100736A2E /* TYPagerViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B072EC061F1E37B100736A2E /* TYPagerViewLayout.m */; };
B082E5791F0E79830084C952 /* PagerViewDmeoController.m in Sources */ = {isa = PBXBuildFile; fileRef = B082E5781F0E79830084C952 /* PagerViewDmeoController.m */; };
C24375D51F4C3F6A007A70B1 /* TestPushViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C24375D41F4C3F6A007A70B1 /* TestPushViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -71,6 +72,8 @@
B072EC061F1E37B100736A2E /* TYPagerViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TYPagerViewLayout.m; sourceTree = "<group>"; };
B082E5771F0E79830084C952 /* PagerViewDmeoController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PagerViewDmeoController.h; sourceTree = "<group>"; };
B082E5781F0E79830084C952 /* PagerViewDmeoController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PagerViewDmeoController.m; sourceTree = "<group>"; };
C24375D31F4C3F6A007A70B1 /* TestPushViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestPushViewController.h; sourceTree = "<group>"; };
C24375D41F4C3F6A007A70B1 /* TestPushViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestPushViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -120,6 +123,8 @@
2B0D5BB71F15FD1F00A4B8B1 /* CollectionViewController.m */,
2B0D5BB81F15FD1F00A4B8B1 /* CustomViewController.h */,
2B0D5BB91F15FD1F00A4B8B1 /* CustomViewController.m */,
C24375D31F4C3F6A007A70B1 /* TestPushViewController.h */,
C24375D41F4C3F6A007A70B1 /* TestPushViewController.m */,
2B0D5BBF1F15FD5100A4B8B1 /* ListViewController.h */,
2B0D5BC01F15FD5100A4B8B1 /* ListViewController.m */,
2B9C0F541F0E11E7009BC0BD /* Main.storyboard */,
Expand Down Expand Up @@ -201,7 +206,6 @@
TargetAttributes = {
2B9C0F471F0E11E7009BC0BD = {
CreatedOnToolsVersion = 8.3.3;
DevelopmentTeam = ZW52Q3KXX4;
LastSwiftMigration = 0830;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -248,6 +252,7 @@
2B9C0F531F0E11E7009BC0BD /* ViewController.m in Sources */,
B072EC071F1E37B100736A2E /* TYTabPagerBar.m in Sources */,
B072EC0A1F1E37B100736A2E /* TYTabPagerController.m in Sources */,
C24375D51F4C3F6A007A70B1 /* TestPushViewController.m in Sources */,
B072EC081F1E37B100736A2E /* TYTabPagerBarCell.m in Sources */,
B0284FE11F1E595D00C733E6 /* TabPagerControllerDemoController.m in Sources */,
B072EC0B1F1E37B100736A2E /* TYTabPagerView.m in Sources */,
Expand Down Expand Up @@ -383,7 +388,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = ZW52Q3KXX4;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = TYPagerControllerDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -399,7 +404,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = ZW52Q3KXX4;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = TYPagerControllerDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
18 changes: 18 additions & 0 deletions TYPagerControllerDemo/CustomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
//

#import "CustomViewController.h"
#import "TestPushViewController.h"

@interface CustomViewController ()
@property (nonatomic, weak) UILabel *label;
@property (nonatomic, weak) UIButton *cancelBtn;
@property (nonatomic, weak) UIButton *pushBtn;
@end

@implementation CustomViewController
Expand All @@ -29,6 +31,7 @@ - (void)viewWillLayoutSubviews
[super viewWillLayoutSubviews];
_label.center = CGPointMake(CGRectGetWidth(self.view.frame)/2, CGRectGetHeight(self.view.frame)/2);
_cancelBtn.center = CGPointMake(_label.center.x,_label.center.y + 100);
_pushBtn.center = CGPointMake(_label.center.x,_label.center.y + 200);
}

- (void)addPageLabel
Expand All @@ -52,6 +55,16 @@ - (void)addButton
cancelBtn.center = CGPointMake(self.view.center.x, self.view.center.y + 60);
[self.view addSubview:cancelBtn];
_cancelBtn = cancelBtn;

//Push another view controller
UIButton *pushBtn = [UIButton buttonWithType:UIButtonTypeSystem];
pushBtn.titleLabel.font = [UIFont systemFontOfSize:21];
[pushBtn setTitle:@"push another controller" forState:UIControlStateNormal];
[pushBtn addTarget:self action:@selector(pushAnotherController) forControlEvents:UIControlEventTouchUpInside];
pushBtn.frame = CGRectMake(0, 0, 100, 40);
pushBtn.center = CGPointMake(self.view.center.x, self.view.center.y + 160);
[self.view addSubview:pushBtn];
_pushBtn = pushBtn;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里添加了一个点击之后push一个新的viewController的按钮

}

- (void)viewWillAppear:(BOOL)animated
Expand All @@ -76,6 +89,11 @@ - (void)didReceiveMemoryWarning {
// Dispose of any resources that can be recreated.
}

- (void)pushAnotherController {
TestPushViewController *pushCon = [[TestPushViewController alloc] init];
[self.navigationController pushViewController:pushCon animated:YES];
}

/*
#pragma mark - Navigation

Expand Down
32 changes: 32 additions & 0 deletions TYPagerControllerDemo/TYPagerController/TYPagerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ - (void)viewDidLoad {
[self.view addSubview:self.layout.scrollView];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.visibleControllers enumerateObjectsUsingBlock:
^(UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj beginAppearanceTransition:YES animated:animated];
}];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.visibleControllers enumerateObjectsUsingBlock:
^(UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj endAppearanceTransition];
}];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.visibleControllers enumerateObjectsUsingBlock:
^(UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj beginAppearanceTransition:NO animated:animated];
}];
}

- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.visibleControllers enumerateObjectsUsingBlock:
^(UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj endAppearanceTransition];
}];
}

Copy link
Author

@Alex1989Wang Alex1989Wang Aug 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加TYPagerController将自己的出现和隐藏和事件传递出去的代码;
不然在TYPagerController上的child view controller在由于去掉导航栏栈中的其他控制器或者去掉presented view controller而导致的出现都不会有事件;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestPushViewController 是CustomViewController上的push按钮弹出的控制器;
在不加和加入以上代码的情况下:
断点TestPushViewController的viewWillAppear和viewWillDisappear事件就能够看到区别;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试了吗

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我自己在使用

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
第一次进入是会有警告,因为viewWillAppear时visibleControllers还不存在没有调用beginAppearanceTransition , viewDidAppear时visibleControllers存在调了endAppearanceTransition 所以有问题

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这个没有考虑到

- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ - (void)scrollToItemAtIndex:(NSInteger)index animate:(BOOL)animate {
return;
}
[self scrollViewWillScrollToView:_scrollView animate:animate];
[_scrollView setContentOffset:CGPointMake(index * CGRectGetWidth(_scrollView.frame),0) animated:NO];
[_scrollView setContentOffset:CGPointMake(index * CGRectGetWidth(_scrollView.frame),0) animated:animate];
[self scrollViewDidScrollToView:_scrollView animate:animate];
}

Expand Down
13 changes: 13 additions & 0 deletions TYPagerControllerDemo/TestPushViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TestPushViewController.h
// TYPagerControllerDemo
//
// Created by JiangWang on 22/08/2017.
// Copyright © 2017 tany. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TestPushViewController : UIViewController

@end
22 changes: 22 additions & 0 deletions TYPagerControllerDemo/TestPushViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// TestPushViewController.m
// TYPagerControllerDemo
//
// Created by JiangWang on 22/08/2017.
// Copyright © 2017 tany. All rights reserved.
//

#import "TestPushViewController.h"

@interface TestPushViewController ()

@end

@implementation TestPushViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor orangeColor];
}

@end