मान लें कि मेरे पास UICollectionView
पर एक व्यू कंट्रोलर है। मैं UICollectionView
और व्यू कंट्रोलर के TouchesBegan
/TouchesMoved
/TouchesEnded
फ़ंक्शंस में गुजरने के लिए टच कैसे प्राप्त कर सकता हूं? मैंने UIScrollViews
के साथ ExclusiveTouch = false
सेट करके कई बार ऐसा किया है और स्पर्श को इसके पर्यवेक्षण में UIScrollView
से गुज़रने की अनुमति दी जाएगी। लेकिन वही दृष्टिकोण UICollectionViews
के साथ काम नहीं करता है। कोई विचार?छिद्रों को यूआईसीओलेक्शन व्यू से गुजरने की अनुमति दें इसके सुपरव्यू
सेट के ऊपर UICollectionView
:
partial class CyanViewController : BaseViewControllerWithCollection
{
/*--------------------------------------------------------------------------------*/
// Constructors
/*--------------------------------------------------------------------------------*/
public CyanViewController (IntPtr handle) : base (handle)
{
}
/*--------------------------------------------------------------------------------*/
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Setup collection view
this.SetupCollectionView();
}
/*--------------------------------------------------------------------------------*/
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
Console.WriteLine ("TouchesBegan");
}
/*--------------------------------------------------------------------------------*/
// Private Methods
/*--------------------------------------------------------------------------------*/
private void SetupCollectionView()
{
Console.WriteLine ("SetupCollectionView");
try
{
// Instantiate collection view
this.CollectionView = new UICollectionView(
this.View.Bounds,
new UICollectionViewFlowLayout() {
ScrollDirection = UICollectionViewScrollDirection.Vertical,
ItemSize = new CGSize(75, 115),
SectionInset = new UIEdgeInsets(20, 20, 20, 20)
}
);
// Setup delegate and data source
this.CollectionView.Delegate = new ProductTypeCollectionViewDelegate(this);
this.CollectionView.DataSource = new ProductTypeCollectionViewDataSource(this);
this.CollectionView.RegisterClassForCell(typeof(BaseCollectionViewCell), BaseCollectionViewCell.s_millaCellId);
}
catch (Exception ex)
{
Console.WriteLine ("Exception : " + ex.Message);
Console.WriteLine ("Exception : " + ex.StackTrace);
}
// Add collection view to view
this.View.AddSubview(this.CollectionView);
}
/*--------------------------------------------------------------------------------*/
// Class: SeedsCollectionViewDataSource
/*--------------------------------------------------------------------------------*/
public class ProductTypeCollectionViewDataSource : UICollectionViewDataSource
{
/*--------------------------------------------------------------------------------*/
// Properties
/*--------------------------------------------------------------------------------*/
private CyanViewController _parentController;
/*--------------------------------------------------------------------------------*/
// Constructors
/*--------------------------------------------------------------------------------*/
public ProductTypeCollectionViewDataSource (
CyanViewController a_parentController
)
{
this._parentController = a_parentController;
}
/*--------------------------------------------------------------------------------*/
private ProductTypeCollectionViewDataSource()
{
throw new NotImplementedException();
}
/*--------------------------------------------------------------------------------*/
// UICollectionViewDataSource Implementation
/*--------------------------------------------------------------------------------*/
public override UICollectionViewCell GetCell (UICollectionView collectionView, NSIndexPath indexPath)
{
var cell = (BaseCollectionViewCell)collectionView.DequeueReusableCell (BaseCollectionViewCell.s_millaCellId, indexPath);
cell.Label.Text = "Woot";
return cell;
}
/*--------------------------------------------------------------------------------*/
public override nint GetItemsCount (UICollectionView collectionView, nint section)
{
return 10;
}
/*--------------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------------*/
// Class: SeedsCollectionViewDelegate
/*--------------------------------------------------------------------------------*/
public class ProductTypeCollectionViewDelegate : UICollectionViewDelegate
{
/*--------------------------------------------------------------------------------*/
// Properties
/*--------------------------------------------------------------------------------*/
private CyanViewController _parentController;
/*--------------------------------------------------------------------------------*/
// Constructors
/*--------------------------------------------------------------------------------*/
public ProductTypeCollectionViewDelegate (
CyanViewController a_parentController
)
{
this._parentController = a_parentController;
}
/*--------------------------------------------------------------------------------*/
private ProductTypeCollectionViewDelegate()
{
throw new NotImplementedException();
}
/*--------------------------------------------------------------------------------*/
// UICollectionViewDelegate Implementation
/*--------------------------------------------------------------------------------*/
public async override void ItemSelected (UICollectionView collectionView, NSIndexPath indexPath)
{
Console.WriteLine ("ItemSelected indexPath.Row = " + indexPath.Row);
}
/*--------------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------------*/
}
अप UIViewController
सेट कि CollectionView
रखती है। मैं TouchesBegan
/Moved
/Ended
में छूना चाहता हूं!
partial class BaseViewControllerWithCollection : UIViewController
{
/*--------------------------------------------------------------------------------*/
// Properties
/*--------------------------------------------------------------------------------*/
public UICollectionView CollectionView { get; set; }
/*--------------------------------------------------------------------------------*/
// Constructors
/*--------------------------------------------------------------------------------*/
public BaseViewControllerWithCollection (IntPtr handle) : base (handle)
{
this.View.ExclusiveTouch = false;
this.View.UserInteractionEnabled = true;
}
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
Console.WriteLine ("TouchesBegan");
}
public override void TouchesMoved (NSSet touches, UIEvent evt)
{
base.TouchesMoved (touches, evt);
Console.WriteLine ("TOuchesMoved");
}
public override void TouchesEnded (NSSet touches, UIEvent evt)
{
base.TouchesEnded (touches, evt);
Console.WriteLine ("TouchesSended");
}
/*--------------------------------------------------------------------------------*/
}
यह मेरी UICollectionView
कक्षा है। मैं UIViewController
में अंतिम रूप नहीं मिल सका तो मैं उन्हें यहाँ हो रही है की कोशिश की, लेकिन नहीं कर सका ....
public class MyCollectionView : UICollectionView
{
public MyCollectionView (CGRect frame, UICollectionViewLayout layout) : base (frame, layout)
{
this.ExclusiveTouch = false;
this.UserInteractionEnabled = true;
this.BackgroundView.UserInteractionEnabled = true;
this.BackgroundView.ExclusiveTouch = false;
}
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
Console.WriteLine ("MyCollectionVIew TouchesBegan");
}
public override void TouchesMoved (NSSet touches, UIEvent evt)
{
base.TouchesMoved (touches, evt);
Console.WriteLine ("MyCollectionVIew TouchesMoved");
}
public override void TouchesEnded (NSSet touches, UIEvent evt)
{
base.TouchesEnded (touches, evt);
Console.WriteLine ("MyCollectionVIew TouchesEnded");
}
}
क्या आप चाहते हैं कि संग्रह संग्रह और अंतर्निहित दृश्य, या केवल अंतर्निहित दृश्य दोनों द्वारा स्पर्श किया जाए? – rdelmar
मैं संग्रह दृश्य को काम करना चाहता हूं, लेकिन जब आप टच्सबैगन/मूव/एंडेड को कैप्चर करने के लिए अंतर्निहित दृश्य रखने के लिए बस टैप करते हैं, या दबाए रखें। तो शायद दोनों। UIScrollViews दोनों कर सकते हैं, इसलिए मैं यह पता लगाने की कोशिश कर रहा हूं कि UICollectionViews क्यों नहीं कर सकता। या अगर वे कर सकते हैं वे कैसे कर सकते हैं? – LampShade