간단한 LINQ 쿼리의 결과가 포함 된 UILabels을 만들고 추가하는 UIScrollView가 있습니다.UISwipeGestureRecogniser가 인식되지 않습니다.
레이블을 생성하는 루프 내에서 UISwipeGestureRecognizer를 설정했습니다 (iOS: issues with UIGestureRecognisers vs Subviews은 각 컨트롤마다 새로운 인식기가 필요하다고 말합니다. 인식기를 추가하기 위해 UIImageView와 동일한 UILabel을 사용할 수 있다고 가정하고 있습니다). 인식자를 레이블에 추가했습니다.
UIScrollView가 포함 된보기가 시작되면 scrollview가 예상대로 작동하지만 스 와이프가 작동하지 않습니다.
경고 : 시뮬레이터에서만 시도했지만 내 iPhone이 작동 중입니다.
private void CreateViewHistory()
{
float xtext = 4f;
float y = 4f;
int c = 0;
var tv = tank.Events.OrderByDescending(t => t.Date).ToList();
tbiHistClearAll.Enabled = enableDelete;
//tgrRemove.AddTarget(this, new Selector("screenSwipe"));
//pgrRemove.DelaysTouchesBegan = true;
foreach (var e in tv)
{
var tgrRemove = new UISwipeGestureRecognizer()
{
NumberOfTouchesRequired = 1,
Direction = UISwipeGestureRecognizerDirection.Right,
};
tgrRemove.AddTarget(this, new Selector("screenSwipe"));
svHistoryEvents.PanGestureRecognizer.RequireGestureRecognizerToFail(tgrRemove);
string info = string.Format("{0} - {1}{2} ({3})\n{4} - {5}\n{6} - {7}\n{8} - {9}", e.EventType, e.Volume, AppDelegate.Self.db.getShortVolumeUnits(), e.Date.ToShortDateString(),
StringUtils.GetString("Sowcrop.Implement"), e.Implement != null ? e.Implement.ImplementType : StringUtils.GetString("Common.NonRecorded"),
StringUtils.GetString("Common.User"), StringUtils.GetString("Common.NonRecorded"),
StringUtils.GetString("Common.Notes"), !string.IsNullOrEmpty(e.Notes) ? e.Notes : StringUtils.GetString("Common.NonRecorded"));
var lbl = new UILabel()
{
UserInteractionEnabled = true
};
lbl = UICreation.MakeLabelWithTag(svHistoryEvents, new RectangleF(xtext, y, 320f, 90f), info, UITextAlignment.Left, UIColor.Black, false, 4, c);
lbl.AddGestureRecognizer(tgrRemove);
svHistoryEvents.AddSubview(lbl);
lblTemp.Add(lbl);
c++;
y += 94f;
}
UIUtils.ResizeScrollView(svHistoryEvents);
}
[Export("screenSwipe")]
public void SwipeRemove(UIGestureRecognizer s)
{
var swipe = s as UIGestureRecognizer;
var tv = tank.Events.OrderByDescending(t => t.Date).ToList();
var txt = swipe.View as UILabel;
switch (swipe.State)
{
case UIGestureRecognizerState.Began:
Console.WriteLine("Swipe began");
break;
case UIGestureRecognizerState.Changed:
Console.WriteLine("Swipe changed");
tv.RemoveAt(txt.Tag);
CreateViewHistory();
break;
case UIGestureRecognizerState.Ended:
Console.WriteLine("Swipe ended");
break;
case UIGestureRecognizerState.Cancelled:
Console.WriteLine("Swipe cancelled");
break;
}
}
MakeLabelWithTag는 스크롤보기에 추가 할 수있는 UILabel을 생성합니다.
여기에 뭔가가 누락 되었습니까? 아니면 스크롤 뷰 내에서 레이블을 유지하면서 특별한 작업을해야합니까?
나는 또한 UISwipeGestureRecogniser in a UIScrollView에 제안 된 것을 시도했지만 여전히 성공하지 못했습니다.