iOS浮动视频窗口,如Youtube应用程序

iOS浮动视频窗口,如Youtube应用程序,ios,objective-c,video,Ios,Objective C,Video,是否有人知道任何现有的库,或任何关于如何获得与Youtube应用程序相同效果的技术 视频可以“最小化”并悬停在屏幕底部-然后可以滑动关闭或触摸以重新最大化 见: 视频播放正常: 视频最小化: (请注意,视频现在位于屏幕右下角的一个小浮动窗口中) 任何人都知道这是如何实现的,是否有任何现有的教程或库可以用来获得同样的效果?听起来很有趣,所以我查看了youtube。视频看起来像是在顶部的16:9框中播放,下面有一个“请参阅”列表。当用户最小化视频时,播放机会随着“请参阅”视图下降到右下角。同时,“还

是否有人知道任何现有的库,或任何关于如何获得与Youtube应用程序相同效果的技术

视频可以“最小化”并悬停在屏幕底部-然后可以滑动关闭或触摸以重新最大化

见:

视频播放正常:

视频最小化:

(请注意,视频现在位于屏幕右下角的一个小浮动窗口中)


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

听起来很有趣,所以我查看了youtube。视频看起来像是在顶部的16:9框中播放,下面有一个“请参阅”列表。当用户最小化视频时,播放机会随着“请参阅”视图下降到右下角。同时,“还可以看到”视图逐渐变为透明

1) 这样设置视图并创建插座。以下是IB中的外观(注意,这两个容器是兄弟容器)

2) 为视频视图提供上下滑动手势识别器:

@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;
    }];
}
我没有在这个项目中添加视频,但它应该会顺道出现。使mpContainer成为MPMoviePlayerController视图的父视图,它看起来应该很酷。

为您的项目使用和自定义代码

希望对您有所帮助。

为类似YouTube应用程序的drag-uiview更新新框架


希望能对您有所帮助。

这是一个swift 3版本,用于@danh先前提供的答案


我也喜欢这种效果,但不需要图书馆。MP播放器的视图的行为与普通视图类似。附加一个向下滑动识别器,并对其位置和帧进行动画处理,您的应用程序将和谷歌的应用程序一样酷s@danh,您可以放置一些简单的代码片段以使事情更清楚。非常感谢。@shabbirh为什么这不是选定的答案?@danh感谢您提供了很酷的解决方案和尝试不同事物的灵感。我添加swift版本作为一个单独的版本solution@famfamfam-抱歉,它早就被删除了。哪一部分给你带来麻烦?嗨。我想问一下什么是集装箱。MpContainer下面的视图或MpContainer后面所有使用屏幕边界修复的视图?在swift 4中测试,[self-MPisminized]==minimized)始终返回true。不要用两个单独的答案回答这个问题,而应该将这两个答案合并为一个。因为它们都是仅链接的答案。您应该将目标页面的相关部分复制到此处,以便在网站关闭时使用。如果视频视图是
UIWebView
,是否可以使用此方法?
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
        })
    }

}