我的视图宽度是设备屏幕的两倍,并且具有向左或向右移动视图的滑动手势识别器。但我已经意识到,如果在最初离屏的视图部分上执行滑动,视图将不会执行手势操作。
private void DoWork(IProgress<ProgressState> progress)
{
IsAnalyzing = true;
progress.Report(new ProgressState(0, "Processing..."));
int count = File.ReadLines(memoryFile).Count();
StreamReader reader = new StreamReader(memoryFile);
string line = "";
int lineIndex = 0;
while ((line = reader.ReadLine()) != null)
{
progress.Report(new ProgressState((int)(((double)lineIndex / count) * 100.0d));
//Process record... (assume time consuming operation)
HexRecord record = HexFileUtil.ParseLine(line);
lineIndex++;
}
progress.Report(new ProgressState(100, "Done."));
IsAnalyzing = false;
}
...
ObservableProgress.CreateAsync<ProgressState>(progress => Task.Run(() => DoWork(progress)))
.Sample(TimeSpan.FromMilliseconds(250)) // Update UI every 250ms
.ObserveOn(this) // Apply progress updates on UI thread
.Subscribe(p =>
{
Progress = p.ProgressPercentage;
Task = p.Task;
});
因此,向左滑动以查看视图的另一半(在屏幕外加载)后,我无法向右滑动。是否可以在屏幕外加载的位置执行手势?
编辑:所以经过一些修补,我发现在屏幕外加载的视图的任何位置都无法识别手势。因此,如果我移动视图以查看从屏幕外开始的50个像素,则不会在50个像素上识别手势。
答案 0 :(得分:0)
我真的不明白你的答案,但希望这会有所帮助
所以我认为你的问题是
或
为.code。
func swipeLeft(sender: UISwipeGestureRecognizer) {
// Moves masterView to the left equal to that of the width of the screen (or half of masterView's total width)
let moveLeftFrame = CGRect(x: -view.frame.width, y: 0, width: masterView.frame.width, height: masterView.frame.height)
UIView.animateKeyframes(withDuration: 0.5, delay: 0, options: .calculationModeCubic, animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.4, animations: {
masterView.frame = moveLeftFrame
})
}, completion: { (true) in
})
}
func swipeRight(sender: UISwipeGestureRecognizer) {
// Moves masterView back to original location
let moveRightFrame = CGRect(x: 0, y: 0, width: masterView.frame.width, height: masterView.frame.height)
UIView.animateKeyframes(withDuration: 0.5, delay: 0, options: .calculationModeCubic, animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.4, animations: {
masterView.frame = moveRightFrame
})
}, completion: { (true) in
})
}