Reputation: 119
I got a UIViewController
that init a UIView
.
This view containing Interactive Elements like UITextField
or UIButton
.
View is added on ViewDidLoad, at the bottom of the method to be sure that when I made it visible it can be reach by user interaction.
But when I show the view, no interaction can be done on this View.
Is this only possible? Am I doing something wrong?
The View
public class AddBusinessEventView : UIView
{
public UILabel LblTitle;
public UITextField TxtType;
public UIButton BtnClose;
public AddBusinessEventView(nfloat bw, nfloat bh)
{
//Bouton pour fermer le popup
BtnClose = new UIButton();
BtnClose.SetImage(UIImage.FromFile("Images/Boutons/lightbox_close.png"), UIControlState.Normal);
BtnClose.Frame = new CGRect(bw - 80, 30, BtnFermer.ImageView.Image.CGImage.Width * 0.5, BtnFermer.ImageView.Image.CGImage.Height * 0.5);
//Doit se trouver par dessus txtSite et ajouté après dans la vue pour se trouvé en premier plan
LblTitle = new UILabel();
LblTitle.Frame = new CGRect((bw - (lw + 200)) / 2, 100, lw + 200, 30);
LblTitle.Text = "Fill with your event elements";
LblTitle.Font = UIFont.FromName("GillSans-Bold", 22);
LblTitle.TextColor = UIColor.FromRGB(211, 3, 67);
LblTitle.TextAlignment = UITextAlignment.Center;
TxtType = new UITextField(new CGRect((bw - 750) / 2, 140, 350, 40));
TxtType.BackgroundColor = UIColor.White;
TxtType.TextAlignment = UITextAlignment.Center;
TxtType.BorderStyle = UITextBorderStyle.RoundedRect;
TxtType.AutocorrectionType = UITextAutocorrectionType.No;
TxtType.AutocapitalizationType = UITextAutocapitalizationType.AllCharacters;
TxtType.Placeholder = "Type";
AddSubviews(BtnClose, LblTitle, TxtType);
}
}
The UIViewController
partial class EvenementViewController : EnhancedUIViewController
{
AddBusinessEventView AddBusinessEventView;
public EvenementViewController(IntPtr handle) : base(handle) { }
public EvenementViewController() : base() { }
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
if (myEvent == null)
{
ShowAddBusinessEventView();
}
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
nfloat bw = View.Bounds.Width;
nfloat bh = View.Bounds.Height;
//Another Elements are adding to view here
//...
AddBusinessEventView = new AddBusinessEventView(bw, bh);
AddBusinessEventView.Hidden = true;
//Much more View.Add with all elements here
//...
View.Add(AddBusinessEventView);
AddBusinessEventView.BtnType.TouchUpInside += BtnClose_TouchUpInside;
}
#region BusinessEventAdd
void ShowAddBusinessEventView()
{
UIView.Animate(duration: 1,
delay: 0,
options: UIViewAnimationOptions.CurveEaseInOut,
animation: () =>
{
AddBusinessEventView.Alpha = 1.0f;
},
completion: () =>
{
AddBusinessEventView.Hidden = false;
AddBusinessEventListener();
}
);
}
void HideAddBusinessEventView()
{
UIView.Animate(duration: 1,
delay: 0,
options: UIViewAnimationOptions.CurveEaseInOut,
animation: () =>
{
AddBusinessEventView.Alpha = 0.0f;
},
completion: () =>
{
AddBusinessEventView.Hidden = true;
RemoveBusinessEventListener();
}
);
}
void BtnClose_TouchUpInside(object sender, EventArgs e)
{
System.Diagnostics.Debug.Print("Touching myself");
}
#endregion
}
please concidere EnhancedViewController as standard UIViewController, I'm juste adding some enhancements to show users a message from an Overlay.
As I said, we can't interact neither with TxtType nor BtnClose.
Edit :
Don't sure if it can help; but when the View
is added to the Main View
on the UIViewController
, it display well, but all user interaction are catches on element under this View
i.e : The AddBusinessEventView
act as a popup, so it covered all other element, when i press an element, if another element adding prior of this View
is under, it's this element rather than the AddBusinessEventView
element that catch the touch event.
As said, the main purpose is to cut View element on different file for more readability and maintenability of this application.enter code here
Upvotes: 2
Views: 334
Reputation: 759
There is no reason you can't do that. You can architect your code like
And then use View1 and View2 in any of Controller.
I tried your code and I got all the things popup correctly. As you said, if view show up on screen but it's element from another View from below that interact with user maybe you can try to bring your View to front.
Try this
View.BringSubviewToFront(AddBusinessEventView);
At the end of your ViewDidLoad function.
Upvotes: 2