我有两个观点; UIView
位于UITableView
之上。我需要知道UIView
何时被淘汰,所以我在其上放置了UIPanGestureRecognizer
。但是,这会创建一个看似错误的UI,因为您希望它背后的UITableView
像您的手指一样移动。
因此,似乎我需要以某种方式配对此平移手势,使其背后的桌面视图移动,至少,直到此覆盖视图消失。
如何配对平移手势以移动UIScrollView
?
注意:如果您想知道封面视图,它实际上是一个UIImageView
,它有一个表视图的快照,并且出于UI原因应用了一个过滤器。
当该视图被淘汰时,它会消失。因此,从用户的角度来看,当他们开始拖动封面视图时,我希望他们一直认为当封面消失时他们正在拖动表格视图。
答案 0 :(得分:0)
假设您有一个视图控制器,其表格设置如下:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate
{
@IBOutlet var tableView: UITableView!
@IBOutlet var scrollView: UIScrollView!
您可以添加几个手势识别器:
var gestureRecognizer1: UIPanGestureRecognizer = UIPanGestureRecognizer()
var gestureRecognizer2: UIPanGestureRecognizer = UIPanGestureRecognizer()
设置您的代理人并将手势识别器添加到滚动视图中:
override func viewDidLoad()
{
super.viewDidLoad()
scrollView.contentSize = CGSizeMake( ) // <-- Set your content size.
scrollView.delegate = self
tableView.delegate = self
gestureRecognizer1.delegate = self
gestureRecognizer2.delegate = self
tableView.addGestureRecognizer(gestureRecognizer1)
scrollView.addGestureRecognizer(gestureRecognizer2)
}
为UIGestureRecognizerDelegate
实施委托方法以识别同时手势:
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
为UIScrollViewDelegate
:
func scrollViewDidScroll(scrollView: UIScrollView)
{
tableView.contentOffset = scrollView.contentOffset
}
}
tableView的移动将同步到滚动视图。
答案 1 :(得分:0)
最后,我决定用[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.Xml.XmlException: Text node cannot appear in this state. Line 1, position 1.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[MonoDroid] at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <0x0003f>
[MonoDroid] at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () <0x00027>
[MonoDroid] at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f>
[MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x0003b>
[MonoDroid] at (wrapper dynamic-method) object.c4ebb548-a354-4444-bc7d-3e13bebb1053 (intptr,intptr) <0x0003b>
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: MyApplication, PID: 32611
[AndroidRuntime] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
[AndroidRuntime] Caused by: java.lang.reflect.InvocationTargetException
[AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Method.java:372)
[AndroidRuntime] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
[AndroidRuntime] ... 1 more
[AndroidRuntime] Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.Xml.XmlException: Text node cannot appear in this state. Line 1, position 1.
[AndroidRuntime] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
[AndroidRuntime] at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <0x0003f>
[AndroidRuntime] at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () <0x00027>
[AndroidRuntime] at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f>
[AndroidRuntime] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x0003b>
[AndroidRuntime] at (wrapper dynamic-method) object.c4ebb548-a354-4444-bc7d-3e13bebb1053 (intptr,intptr) <0x0003b>
[AndroidRuntime]
[AndroidRuntime] at mono.java.lang.RunnableImplementor.n_run(Native Method)
[AndroidRuntime] at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
[AndroidRuntime] at android.os.Handler.handleCallback(Handler.java:739)
[AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:95)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:145)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:5942)
[AndroidRuntime] ... 4 more
[Process] Sending signal. PID: 32611 SIG: 9
直接更改单元格的图像,而不是拍摄快照。无论如何,这种方式应该是我应该做的,它更清洁,并且不会使用任何可能有问题的“变通方法”。