iOS Question Page_Resize event

ilan

Expert
Licensed User
Longtime User
hi

i have an ios app that has 3 pages. when i switch between the pages i see that the Show sub will be called first then will the _Appear sub then the _Resize will be called.

on my phone everything is working well i tested it also on the simulator and it is working as expected.

today i talked to a user about another issue he had with my app but then he also complained about my app been zoomed out on his phone. he said that in the beginning when he used the app it was ok and after a while it start to show the page zoomed out.


this is how it looks on his phone:

IMG-20160915-WA0000.jpg

this is how it should look:

Screenshot_2016-07-27-23-26-59.png

what could be the reason for that?

in the layout file "Handle Resize" is unchecked because i hande resize in code with resize sub.

i use variant 414x736 and my resize event look like this:

B4X:
Private Sub mysalary_Resize(Width As Int, Height As Int) 'resize sub '| nr. 3
    Log("mysalary resize sub")
  
    'start rexize all views
    ratiox = Width/414 'iphone 6+ 5.5" = x414
    ratioy = Height/716 'iphone 6+ 5.5" = y736 - 20!
  
    density = GetDeviceLayoutValues.DeviceApproximateScreenSize / 5.27
  
    For Each v As View In mysalary.RootPanel.GetAllViewsRecursive
        If Not(v.Tag = "dnrm") Then
            v.Width = v.Width*ratiox
            v.Height = v.Height*ratioy
            v.Left = v.Left*ratiox
            v.Top = v.Top*ratioy
        End If
      
        If v Is Label Then
            Dim lbl As Label = v
            Dim fontsize As Int = lbl.Font.Size
            Dim fontname As String = lbl.Font.Name
            lbl.Font = Font.CreateNew2(fontname, fontsize*density)
        else if v Is Button Then
            Dim btn As Button = v
            Dim fontsize As Int = btn.CustomLabel.Font.Size
            Dim fontname As String = btn.CustomLabel.Font.Name
            btn.CustomLabel.Font = Font.CreateNew2(fontname, fontsize*density)
        else if v Is TextField Then
            Dim txtf As TextField = v
            Dim fontsize As Int = txtf.Font.Size
            Dim fontname As String = txtf.Font.Name
            txtf.Font = Font.CreateNew2(fontname, fontsize*density)
        End If  
    Next
  
    loadvalues
    addtosv(salaryp1) 'load page1
End Sub
 

ilan

Expert
Licensed User
Longtime User
i forgot to mention that he said that when the page is loading it is loading correctly only then the ad is shown and when he clicks on the X (to close the app) then the page looks zoomed out.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
in the layout file "Handle Resize" is unchecked because i hande resize in code with resize sub.
Why? It would have been easier to use anchors and designer script. If there is anything specific that you need to do programmatically then do it in the Page_Resize event.

I don't understand your code but it is not needed. There are much simpler solutions.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i tried it with anchors but i didnot get the result i wanted. i will try again.

the code above just resize all views and textsize of all views with the same ratio to each screen so you get a zoomed in effect.
i know we had that discussion in the past. i just did it with all my ios apps and in this app i used the same template. i guess its time to
update that b4i template :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
another question (it is related to this topic)

the _Resize(Width as int, Height as int) is part of page object?

when i write Sub (space) then Tab and select Page i dont see _Resize event
i only see _Appear, _DisAppear, _BarButtonClick and _KeyboardStateChange

thanx, ilan
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
And this event should be fired every time a page is shown that is not intialized or when the size of the page is changed like portrait to landscape, correct?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
ok, i could now reproduce the issue and get that behavior

when the page is loaded the resize event will be raised and what it does is it is going recursive all views and changing their height/weight according to the ratio i set

so when page is firsttime initialized and loading the layout all views are set to iphone 6+ size so when i resize them to my iphone it looks fine but when i am in my app and get a phone call the resize event will be called again and now the views are resized again and this is the reason everything shrinks.

i need to tell in resize event that if the page was already resized dont resize again.
maybe put a boolean FirstTime and set it in resize event to true (at the end of the event) and on the top if firsstime then return

like this that event wont be called twice.

EDIT: this is not good, it is happening on all my apps. when i answer the incomming call while i am in my app that behavior will happen if i wont answer it will work fine. weird :confused:
will need to update all my apps.
 
Upvote 0
Top