像Youtube应用程序的iOS浮动video窗口

有没有人知道任何现有的图书馆,或任何技术如何获得在Youtube应用程序中find相同的效果。

video可以“最小化”,并hover在屏幕的底部 – 然后可以滑动closures或触摸重新最大化。

看到:

正常播放video: https : //www.dropbox.com/s/o8c1ntfkkp4pc4q/2014-06-07%2001.19.20.png

video最小化: https : //www.dropbox.com/s/w0syp3infu21g08/2014-06-07%2001.19.27.png

(注意video是如何在屏幕右下方的一个小浮动窗口中)。

任何人都知道这是如何实现的,如果有任何现有的教程或库可以用来获得相同的效果?

更新新的框架FWDraggableSwipePlayer拖动uiview像YouTube应用程序。

希望能帮到你。

听起来很有趣,所以我看着YouTube。 video看起来像是在顶部的16:9框中播放,下面还有“另请参见”列表。 当用户最小化video时,播放器会随着“另见”视图下降到右下angular。 同时,这个“另见”观点也渐渐淡化。

1)像这样设置视图并创build网点。 这是IB的样子。 (请注意,这两个容器是兄弟姐妹)

在这里输入图像说明

2)给video视图向上滑动并向下滑动手势识别器:

 @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *tallMpContainer; @property (weak, nonatomic) IBOutlet UIView *mpContainer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)]; UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)]; swipeUp.direction = UISwipeGestureRecognizerDirectionUp; swipeDown.direction = UISwipeGestureRecognizerDirectionDown; [self.mpContainer addGestureRecognizer:swipeUp]; [self.mpContainer addGestureRecognizer:swipeDown]; } - (void)swipeDown:(UIGestureRecognizer *)gr { [self minimizeMp:YES animated:YES]; } - (void)swipeUp:(UIGestureRecognizer *)gr { [self minimizeMp:NO animated:YES]; } 

3)然后是了解当前状态的方法,并改变当前状态。

 - (BOOL)mpIsMinimized { return self.tallMpContainer.frame.origin.y > 0; } - (void)minimizeMp:(BOOL)minimized animated:(BOOL)animated { if ([self mpIsMinimized] == minimized) return; CGRect tallContainerFrame, containerFrame; CGFloat tallContainerAlpha; if (minimized) { CGFloat mpWidth = 160; CGFloat mpHeight = 90; // 160:90 == 16:9 CGFloat x = 320-mpWidth; CGFloat y = self.view.bounds.size.height - mpHeight; tallContainerFrame = CGRectMake(x, y, 320, self.view.bounds.size.height); containerFrame = CGRectMake(x, y, mpWidth, mpHeight); tallContainerAlpha = 0.0; } else { tallContainerFrame = self.view.bounds; containerFrame = CGRectMake(0, 0, 320, 180); tallContainerAlpha = 1.0; } NSTimeInterval duration = (animated)? 0.5 : 0.0; [UIView animateWithDuration:duration animations:^{ self.tallMpContainer.frame = tallContainerFrame; self.mpContainer.frame = containerFrame; self.tallMpContainer.alpha = tallContainerAlpha; }]; } 

我没有添加video到这个项目,但它应该只是放在。使mpContainer MPMoviePlayerController的视图的父视图,它应该看起来很酷。

使用TFSwipeShrink并为您的项目定制代码。

希望能帮到你。

这是一个快速的3版本,用于@danh之前提供的答案。

https://stackoverflow.com/a/24107949/1211470

 import UIKit class ViewController: UIViewController { @IBOutlet weak var tallMpContainer: UIView! @IBOutlet weak var mpContainer: UIView! var swipeDown: UISwipeGestureRecognizer? var swipeUp: UISwipeGestureRecognizer? override func viewDidLoad() { super.viewDidLoad() swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(swipeDownAction)) swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(swipeUpAction)) swipeDown?.direction = .down swipeUp?.direction = .up self.mpContainer.addGestureRecognizer(swipeDown!) self.mpContainer.addGestureRecognizer(swipeUp!) } @objc func swipeDownAction() { minimizeWindow(minimized: true, animated: true) } @objc func swipeUpAction() { minimizeWindow(minimized: false, animated: true) } func isMinimized() -> Bool { return CGFloat((self.tallMpContainer?.frame.origin.y)!) > CGFloat(20) } func minimizeWindow(minimized: Bool, animated: Bool) { if isMinimized() == minimized { return } var tallContainerFrame: CGRect var containerFrame: CGRect var tallContainerAlpha: CGFloat if minimized == true { let mpWidth: CGFloat = 160 let mpHeight: CGFloat = 90 let x: CGFloat = 320-mpWidth let y: CGFloat = self.view.bounds.size.height - mpHeight; tallContainerFrame = CGRect(x: x, y: y, width: 320, height: self.view.bounds.size.height) containerFrame = CGRect(x: x, y: y, width: mpWidth, height: mpHeight) tallContainerAlpha = 0.0 } else { tallContainerFrame = self.view.bounds containerFrame = CGRect(x: 0, y: 0, width: 320, height: 180) tallContainerAlpha = 1.0 } let duration: TimeInterval = (animated) ? 0.5 : 0.0 UIView.animate(withDuration: duration, animations: { self.tallMpContainer.frame = tallContainerFrame self.mpContainer.frame = containerFrame self.tallMpContainer.alpha = tallContainerAlpha }) } }