Skip to content

Commit

Permalink
修复不同层级结构转屏的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
renzifeng committed Aug 4, 2020
1 parent d75adf5 commit 488085f
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 55 deletions.
12 changes: 6 additions & 6 deletions Example/ZFPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
D209360120B658AE0002C956 /* data.json in Resources */ = {isa = PBXBuildFile; fileRef = D20935F620B658AE0002C956 /* data.json */; };
D209360220B658AE0002C956 /* NSString+Size.m in Sources */ = {isa = PBXBuildFile; fileRef = D20935FB20B658AE0002C956 /* NSString+Size.m */; };
D209360320B658AE0002C956 /* ZFLightTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D20935FC20B658AE0002C956 /* ZFLightTableViewController.m */; };
D209360A20B659190002C956 /* ZFNoramlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D209360920B659190002C956 /* ZFNoramlViewController.m */; };
D209360A20B659190002C956 /* ZFNormalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D209360920B659190002C956 /* ZFNormalViewController.m */; };
D227504D21491289002DE221 /* ZFPlayerDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D227504C21491289002DE221 /* ZFPlayerDetailViewController.m */; };
D23F3D9722A67DAD00BC4E19 /* ZFRotationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D23F3D9522A67DAD00BC4E19 /* ZFRotationViewController.xib */; };
D23F3DA322A7589A00BC4E19 /* ZFScrollViewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D23F3DA222A7589A00BC4E19 /* ZFScrollViewViewController.m */; };
Expand Down Expand Up @@ -120,8 +120,8 @@
D20935FA20B658AE0002C956 /* ZFTableData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFTableData.h; sourceTree = "<group>"; };
D20935FB20B658AE0002C956 /* NSString+Size.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Size.m"; sourceTree = "<group>"; };
D20935FC20B658AE0002C956 /* ZFLightTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFLightTableViewController.m; sourceTree = "<group>"; };
D209360820B659190002C956 /* ZFNoramlViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFNoramlViewController.h; sourceTree = "<group>"; };
D209360920B659190002C956 /* ZFNoramlViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFNoramlViewController.m; sourceTree = "<group>"; };
D209360820B659190002C956 /* ZFNormalViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFNormalViewController.h; sourceTree = "<group>"; };
D209360920B659190002C956 /* ZFNormalViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFNormalViewController.m; sourceTree = "<group>"; };
D227504B21491289002DE221 /* ZFPlayerDetailViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZFPlayerDetailViewController.h; sourceTree = "<group>"; };
D227504C21491289002DE221 /* ZFPlayerDetailViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZFPlayerDetailViewController.m; sourceTree = "<group>"; };
D23F3D9522A67DAD00BC4E19 /* ZFRotationViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ZFRotationViewController.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -396,8 +396,8 @@
D209360720B659070002C956 /* Normal */ = {
isa = PBXGroup;
children = (
D209360820B659190002C956 /* ZFNoramlViewController.h */,
D209360920B659190002C956 /* ZFNoramlViewController.m */,
D209360820B659190002C956 /* ZFNormalViewController.h */,
D209360920B659190002C956 /* ZFNormalViewController.m */,
);
path = Normal;
sourceTree = "<group>";
Expand Down Expand Up @@ -705,7 +705,7 @@
D273160624B9F6FD0033AED1 /* ZFWChatViewController.m in Sources */,
D20935FD20B658AE0002C956 /* ZFTableViewCellLayout.m in Sources */,
D23F3DAB22A761C500BC4E19 /* ZFADViewController.m in Sources */,
D209360A20B659190002C956 /* ZFNoramlViewController.m in Sources */,
D209360A20B659190002C956 /* ZFNormalViewController.m in Sources */,
D227504D21491289002DE221 /* ZFPlayerDetailViewController.m in Sources */,
CC112E9D20DBD6600051EE60 /* ZFOtherCell.m in Sources */,
D2B982712136405500B4A0B9 /* ZFFullScreenViewController.m in Sources */,
Expand Down
108 changes: 99 additions & 9 deletions Example/ZFPlayer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="zew-mS-chL">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="RRr-5J-NP9">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<!--Item-->
<scene sceneID="ltZ-jG-haX">
<objects>
<navigationController id="zew-mS-chL" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Item" id="wCa-2A-PB9"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="972-a3-Fpt">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand All @@ -23,7 +22,7 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4s6-sX-OfE" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-617" y="-716"/>
<point key="canvasLocation" x="320.80000000000001" y="-716.49175412293857"/>
</scene>
<!--View Controller-->
<scene sceneID="mmb-D2-2HN">
Expand All @@ -42,7 +41,98 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qVu-5c-CqI" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="291" y="-713"/>
<point key="canvasLocation" x="1229.5999999999999" y="-713.79310344827593"/>
</scene>
<!--Item-->
<scene sceneID="Esh-IW-Q5j">
<objects>
<navigationController id="mvl-nb-jWj" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Item" id="WMw-Ag-FNE"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="rrz-YB-HlK">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="2sB-XX-DZf" kind="relationship" relationship="rootViewController" id="4wj-kv-plE"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="uEX-An-FHX" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="321" y="860"/>
</scene>
<!--点击播放-->
<scene sceneID="2nk-BJ-JEs">
<objects>
<viewController id="2sB-XX-DZf" customClass="ZFNotAutoPlayViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Rw4-qi-Ksf"/>
<viewControllerLayoutGuide type="bottom" id="qcm-mO-Zu2"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Puf-u0-ly3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
<navigationItem key="navigationItem" title="点击播放" id="UMW-YX-LW8"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="onu-hd-cbm" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1230" y="860"/>
</scene>
<!--Item-->
<scene sceneID="EYd-k4-KPe">
<objects>
<navigationController id="H0e-mn-OvH" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Item" id="3hs-oD-TkD"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="8QN-ql-OMR">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="CI9-TV-vQN" kind="relationship" relationship="rootViewController" id="UVp-Yv-fxx"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dBK-Mx-Lgp" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="321" y="103"/>
</scene>
<!--点击播放-->
<scene sceneID="bFh-HM-iA9">
<objects>
<viewController id="CI9-TV-vQN" customClass="ZFNotAutoPlayViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="p8n-31-ybx"/>
<viewControllerLayoutGuide type="bottom" id="ZPN-gf-SQl"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="0z4-Lu-I83">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
<navigationItem key="navigationItem" title="点击播放" id="4RZ-TL-abN"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="aPn-Wj-9oE" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1230" y="103"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="NaC-cA-sHI">
<objects>
<tabBarController automaticallyAdjustsScrollViewInsets="NO" id="RRr-5J-NP9" sceneMemberID="viewController">
<toolbarItems/>
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="cqh-hS-LV8">
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>
<connections>
<segue destination="zew-mS-chL" kind="relationship" relationship="viewControllers" id="zlq-S2-Z9c"/>
<segue destination="H0e-mn-OvH" kind="relationship" relationship="viewControllers" id="5Mm-S5-ibe"/>
<segue destination="mvl-nb-jWj" kind="relationship" relationship="viewControllers" id="Pdk-XV-COJ"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="TDn-Ns-8Cv" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1057" y="103"/>
</scene>
</scenes>
</document>
3 changes: 2 additions & 1 deletion Example/ZFPlayer/Main/ZFViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)viewDidLoad {
}

- (NSArray <ZFTableItem *>*)createItemsByPlayerType {
return @[[ZFTableItem itemWithTitle:@"普通样式" subTitle:@"Normal style" viewControllerName:@"ZFNoramlViewController"],
return @[[ZFTableItem itemWithTitle:@"普通样式" subTitle:@"Normal style" viewControllerName:@"ZFNormalViewController"],
[ZFTableItem itemWithTitle:@"UITableView样式" subTitle:@"UITableView style" viewControllerName:@"ZFAutoPlayerViewController"],
[ZFTableItem itemWithTitle:@"UICollectionView样式" subTitle:@"UICollectionView style" viewControllerName:@"ZFCollectionViewController"],
[ZFTableItem itemWithTitle:@"UIScrollView样式" subTitle:@"UIScrollView style" viewControllerName:@"ZFScrollViewViewController"]];
Expand Down Expand Up @@ -118,6 +118,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[(ZFDouYinViewController *)viewController playTheIndex:0];
}
viewController.navigationItem.title = itme.title;
viewController.hidesBottomBarWhenPushed = YES;

if ([vcString isEqualToString:@"ZFDouyinCollectionViewController"] && [itme.title isEqualToString:@"横向滚动抖音"]) {
ZFDouyinCollectionViewController *douyinVC = (ZFDouyinCollectionViewController *)viewController;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ZFNoramlViewController.h
// ZFNormalViewController.h
// ZFPlayer
//
// Created by 紫枫 on 2018/3/21.
Expand All @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>

@interface ZFNoramlViewController : UIViewController
@interface ZFNormalViewController : UIViewController


@end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// ZFNoramlViewController.m
// ZFNormalViewController.m
// ZFPlayer
//
// Created by 紫枫 on 2018/3/21.
// Copyright © 2018年 紫枫. All rights reserved.
//

#import "ZFNoramlViewController.h"
#import "ZFNormalViewController.h"
#import <ZFPlayer/ZFAVPlayerManager.h>
#import <ZFPlayer/ZFIJKPlayerManager.h>
#import <ZFPlayer/ZFPlayerControlView.h>
Expand All @@ -18,7 +18,7 @@

static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";

@interface ZFNoramlViewController ()
@interface ZFNormalViewController ()
@property (nonatomic, strong) ZFPlayerController *player;
@property (nonatomic, strong) UIImageView *containerView;
@property (nonatomic, strong) ZFPlayerControlView *controlView;
Expand All @@ -29,7 +29,7 @@ @interface ZFNoramlViewController ()

@end

@implementation ZFNoramlViewController
@implementation ZFNormalViewController

- (void)viewDidLoad {
[super viewDidLoad];
Expand Down
24 changes: 19 additions & 5 deletions Example/ZFPlayer/ScrollView/ZFScrollViewViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ - (void)viewDidLoad {
self.player.playerApperaPercent = 0.0;
/// 播放小窗相关
self.player.stopWhileNotVisible = NO;
self.player.shouldAutoPlay = NO;

CGFloat margin = 20;
CGFloat w = ZFPlayer_ScreenWidth/2;
CGFloat h = w * 9/16;
Expand Down Expand Up @@ -90,24 +92,36 @@ - (BOOL)shouldAutorotate {
#pragma mark - action

- (void)playClick:(UIButton *)sender {
NSString *URLString = [@"http://flv3.bn.netease.com/tvmrepo/2018/6/H/9/EDJTRBEH9/SD/EDJTRBEH9-mobile.mp4" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
self.player.currentPlayerManager.assetURL = [NSURL URLWithString:URLString];
self.player.currentPlayerManager.assetURL = [NSURL URLWithString:@"https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4"];
[self.controlView showTitle:@"UIScrollView播放" coverURLString:@"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" fullScreenMode:ZFFullScreenModeAutomatic];
}

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[scrollView zf_scrollViewDidEndDecelerating];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[scrollView zf_scrollViewDidEndDraggingWillDecelerate:decelerate];
}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
[scrollView zf_scrollViewDidScrollToTop];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[scrollView zf_scrollViewDidScroll];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[scrollView zf_scrollViewWillBeginDragging];
}

#pragma mark - about keyboard orientation

/// 键盘支持横屏,这里必须设置支持多个方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if (self.player.isFullScreen) {
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
#pragma mark - ZFDouYinCellDelegate

- (void)zf_douyinRotation {
/// 这里要强转方向
self.player.orientationObserver.forceRotaion = YES;
UIInterfaceOrientation orientation = UIInterfaceOrientationUnknown;
if (self.player.isFullScreen) {
orientation = UIInterfaceOrientationPortrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ - (void)viewDidLoad {
};
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.player.viewControllerDisappear = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.player.viewControllerDisappear = YES;
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
Expand Down
5 changes: 4 additions & 1 deletion ZFPlayer/Classes/Core/UIScrollView+ZFPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,10 @@ - (BOOL)zf_viewControllerDisappear {
}

- (BOOL)zf_stopPlay {
return [objc_getAssociatedObject(self, _cmd) boolValue];
NSNumber *number = objc_getAssociatedObject(self, _cmd);
if (number) return number.boolValue;
self.zf_stopPlay = YES;
return YES;
}

- (BOOL)zf_stopWhileNotVisible {
Expand Down
4 changes: 2 additions & 2 deletions ZFPlayer/Classes/Core/ZFOrientationObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ typedef NS_OPTIONS(NSUInteger, ZFDisablePortraitGestureTypes) {
/// Container view of a small screen state player.
@property (nonatomic, weak) UIView *containerView;

/// Use device orientation, default YES.
@property (nonatomic, assign) BOOL forceDeviceOrientation;
/// Force Rotaion, default NO.
@property (nonatomic, assign) BOOL forceRotaion;

/// The block invoked When player will rotate.
@property (nonatomic, copy, nullable) void(^orientationWillChange)(ZFOrientationObserver *observer, BOOL isFullScreen);
Expand Down
Loading

0 comments on commit 488085f

Please sign in to comment.