0

I make a Today Notification Widget and I use AutoLayout. When I press a number button, whole view moves to left. I cannot figure out why.

Why view moves left when I tap a button? Is it from AutoLayout or is a general problem?

Before touch

After touch

Image1enter image description here

Image2enter image description here

Image3enter image description here

Silviu St
  • 1,810
  • 3
  • 33
  • 42
  • You have a bug on line 172 of your widget's code. I can tell because I have ESP. For those of your readers who *don't* have ESP, you might want to post your code... – Duncan C Aug 12 '15 at 18:17
  • 2
    Hey @DuncanC. Thanks for your reply. I'm kindda new to AutoLayout, and I understand your irony. Programatically I only change the color of the button when it's pressed and then set to the UILabel the amount selected. Can you tell me what from autolayout to post to provide a clue of what is happening? – Silviu St Aug 12 '15 at 18:22
  • ..your label can be the reason, you have any constraints attached to its behaviour or you are changing it width making the full view to depend on it? If its possible add an screenshot of your constraints that refers to such label – Hugo Alonso Aug 12 '15 at 18:28
  • Label has no constrains attached, I tried earlier almost everything. I will edit my question with screenshots of constrains for views right away – Silviu St Aug 12 '15 at 18:32
  • The UI item that changes from "350" to "3"-- what kind is it, a label or a text field? And what constraints do you have that affect it? – Tom Harrington Aug 12 '15 at 22:19

1 Answers1

1

This appears to be a problem with your implementation. There's no reason for this to happen unless you are changing some positions or autolayout constraints when tapping a button. also, you may want to take a look at widgetMarginInsetsForProposedMarginInsets function and that you are already inheriting from NCWidgetProviding:

class MainViewController: UIViewController, NCWidgetProviding {

 func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
    return UIEdgeInsetsZero
 }
}

...anyway, your question is really broad the way it's stated here, maybe you will want to add some source for further insight.

Hope it helps!

UPDATE:

The problem is that when you input some text, the margins of that view get's bigger, and that's doing something weird because there is some constraint that you are missing and that is related to the view (your UITextField/UILabel) that is giving value to your right side leading margin constraint.

If you isolate completely, right part from Left, maybe putting both of them in separated views. You should be able to resolve this issue as any changes inside of the left view, remains in the left view.

Other way is to remove all constrains and start over, putting your constrains manually, do not let xcode do that job for you

Hugo Alonso
  • 6,684
  • 2
  • 34
  • 65
  • Thanks for your reply Hugo. Programatically I change nothing and I use Objective C. Can you tell me what to provide? – Silviu St Aug 12 '15 at 18:24
  • In objective-C that function and inheritance also exists, just in a different format :) ..for now give some more insight about what constraints do you have that can be anyway related to those actions and debug your widget to see if any of them is breaking apart after clicking on that button – Hugo Alonso Aug 12 '15 at 18:31
  • Did you managed to debug your app? there are two things that come into my head. One, a constraint from your right view's leading is getting loose, notice that after changing text it becomes more wider, are you sure that there isn't any constraint attached to your label..if it is so, add some, set an static width at the same width that you number pad. – Hugo Alonso Aug 12 '15 at 18:59
  • 1
    Okay, you have right.(It's a TextField)and if I comment the setting text code, won't do that ugly thing. Although I did what you suggested but it's still changing – Silviu St Aug 12 '15 at 19:10
  • so..any luck with that? – Hugo Alonso Aug 12 '15 at 20:30
  • I took a break. I will try again tomorrow – Silviu St Aug 12 '15 at 20:31