gpt4 book ai didi

ios - 平移以擦洗视频时考虑当前时间

转载 作者:行者123 更新时间:2023-12-01 20:04:14 25 4
gpt4 key购买 nike

这是与平移/可删除视频相关的代码。当前问题发生在第二次滑动手势与第一次滑动的最后位置有一个增量时。换句话说,这段代码需要考虑到视频的当前时间以防止跳过。

```

func didSwipe(panGR: UIPanGestureRecognizer) {

let translation = panGR.translationInView(self.view)
var horizontalTranslation = Float(translation.x)

let durationInSeconds = Float(CMTimeGetSeconds(self.playerView.player.player.currentItem!.asset.duration))

// Using 275 as the limit for delta along x
let translationLimit: Float = 275
let minTranslation: Float = -1 * translationLimit
let maxTranslation: Float = translationLimit

if horizontalTranslation > maxTranslation {
horizontalTranslation = maxTranslation
}

if horizontalTranslation < minTranslation {
horizontalTranslation = minTranslation
}


let timeToSeekTo = normalize(horizontalTranslation , minDelta: minTranslation, maxDelta: maxTranslation, minDuration: 0, maxDuration: durationInSeconds)
print("horizontal translation \(horizontalTranslation) \n timeToSeekTo: \(timeToSeekTo)")

self.playerView.player.startScrubbing()
self.playerView.player.scrub(timeToSeekTo)
self.playerView.player.stopScrubbing()
}

func normalize(delta: Float, minDelta: Float, maxDelta: Float, minDuration: Float, maxDuration: Float) -> Float {

let result = ((delta - minDelta) * (maxDuration - minDuration) / (maxDelta - minDelta) + minDuration)
return result
}

```

我将开始时间设置为正好是视频长度的一半。这会在任一方向产生良好的第一次滑动结果。它在第二次和随后的滑动中有明显的跳跃,因为它没有考虑视频的当前时间(我认为)。

最佳答案

这是我使用 normalize 函数编写的代码,并显示当前速率(以及根据播放器速率改变大小的播放图标:

- (IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
[self.rateLabel setHidden:FALSE];
[self animatePlayerControl:@"▷" size:1.0];
[UIView animateWithDuration:0.375 animations:^{
(self.playerControlsLabel).alpha = 0.5f;
}];
} else if (sender.state == UIGestureRecognizerStateEnded) {
[self.rateLabel setHidden:FALSE]; // set to TRUE after testing or remove hiding altogether
//[self.delegate setRate:oldRate];
//[self animatePlayerControl:@"□" size:1.0];
//[_ChromaEpsilonGammaAppDelegate.playerViewController setRate:0.0];
//[_ChromaEpsilonGammaAppDelegate.playerViewController stop];
[UIView animateWithDuration:0.375 animations:^{
(self.playerControlsLabel).alpha = 0.0f;
}];
} else if (sender.state == UIGestureRecognizerStateChanged){
CGPoint location = [sender locationInView:self];
float nlx = ((location.x / ((CGRectGetMidX(self.frame) / (self.frame.size.width / 2.0)))) / (self.frame.size.width / 2.0)) - 1.0;
//float nly = ((location.y / ((CGRectGetMidY(self.view.frame) / (self.view.frame.size.width / 2.0)))) / (self.view.frame.size.width / 2.0)) - 1.0;
nlx = nlx * 2.0;
[self.delegate setRate:nlx];
if (nlx > 0.0) [self animatePlayerControl:@"▷" size:nlx];
else if (nlx < 0.0) [self animatePlayerControl:@"◁" size:fabs(nlx)];
(self.rateLabel).text = [NSString stringWithFormat:@"%.2f", [self.delegate rate]];
}
}

标签设置,可以去任何地方,而不仅仅是在 drawRect 方法中:
- (void)drawRect:(CGRect)rect {
(self.brightnessLabel).textColor = [UIColor colorWithWhite:1.0 alpha:1.0];
(self.brightnessLabel).font = [UIFont preferredFontForTextStyle:@"Apple Symbol"];
(self.brightnessLabel).textAlignment = NSTextAlignmentCenter;
(self.contrastLabel).textColor = [UIColor colorWithWhite:1.0 alpha:1.0];
(self.contrastLabel).font = [UIFont preferredFontForTextStyle:@"Apple Symbol"];
(self.contrastLabel).textAlignment = NSTextAlignmentCenter;
_attrsDictionary = @{NSFontAttributeName: [UIFont systemFontOfSize:24.0 weight:UIFontWeightLight]};
}

并且,自动调整播放器图标大小代码:
- (void)animatePlayerControl:(NSString *)labelText size:(float)size {
(self.playerControlsLabel).textColor = [UIColor colorWithWhite:1.0 alpha:1.0];
(self.playerControlsLabel).font = [UIFont preferredFontForTextStyle:@"Apple Symbol"];
(self.playerControlsLabel).textAlignment = NSTextAlignmentCenter;
NSDictionary *attrsDictionary = @{NSFontAttributeName: [UIFont systemFontOfSize:fabs(48.0 * size) weight:UIFontWeightUltraLight]};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:labelText attributes:attrsDictionary];
(self.playerControlsLabel).attributedText = attrString;
}

播放器图标只是 Apple Symbol 字体中的一个字符。

关于ios - 平移以擦洗视频时考虑当前时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39353645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com