iOS Question [SOLVED] How to parse NSRect (to get navbar height)

Sandman

Expert
Licensed User
Longtime User
This is regarding me making my own navbar (see this thread for more info), and I need to get the correct height of it. I already know that the navbar is 44 pixels, but I want to get the value programmatically. (Why? Because all of a sudden Apple might change the iOS design a little bit, and I want my fake navbar to continue look correct.)

This is as far as I've got:
B4X:
Sub test
   
    Dim nav As NavigationController
    nav.Initialize("")
    Dim bar As NativeObject = nav
    Dim i As Object
    i = bar.GetField("navigationBar").GetField("frame")

    Log(i) ' Shows "NSRect: {{0, 0}, {0, 44}}"
    Log(bar.ArrayFromRect(i)) ' Crash

End Sub


I've seen this post which says to parse the NSRect as a string. That feels a little bit like a dirty workaround (that I'm not dismissing as a solution), but it's a somewhat old post so I thought there might be some updates?

I found ArrayFromRect, which sounds to be what I would need. I tried using it as best I could figure out, but it crashes with this message:
B4X:
Error occurred on line: 86 (Main)
-[NSConcreteValue bytes]: unrecognized selector sent to instance 0x28170d740
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 1412
  CoreFoundation       _CF_forwarding_prep_0 + 92
  FS Test              -[B4INativeObject ArrayFromRect:] + 104
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  FS Test              +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  FS Test              -[B4IShell runMethod:] + 448
 FS Test              -[B4IShell raiseEventImpl:method:args::] + 1640
 FS Test              -[B4IShellBI raiseEvent:event:params:] + 1372
 FS Test              +[B4IDebug delegate:::] + 80
 FS Test              -[b4i_main _test] + 208
 FS Test              -[b4i_main _initapp:] + 1768
 FS Test              -[b4i_main _application_start:] + 524
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 FS Test              +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 FS Test              -[B4IShell runMethod:] + 448
 FS Test              -[B4IShell raiseEventImpl:method:args::] + 2164
 FS Test              -[B4IShellBI raiseEvent:event:params:] + 1372
 FS Test              __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
 libdispatch.dylib    <redacted> + 24
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1012
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1964
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 100
 UIKitCore            UIApplicationMain + 212
 FS Test              main + 124
 libdyld.dylib        <redacted> + 4
)
 
Top