iOS Question [SOLVED] How to use an OBJC code

Star-Dust

Expert
Licensed User
Longtime User
I wanted to rotate them on all three axes. I found this code (here)
How can I do it in B4i?
B4X:
// flipping view along axis
// this will rotate view in 3D along any axis

[UIView beginAnimations:nil context:nil];
CATransform3D _3Dt = CATransform3DRotate(self.layer.transform, 3.14, 1.0, 0.0,0.0);
[UIView setAnimationRepeatCount:100];
[UIView setAnimationDuration:0.08];
self.layer.transform=_3Dt;
[UIView commitAnimations]
 

JordiCP

Expert
Licensed User
Longtime User
This a small working example :)

IMG-0179.PNG

The code
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
  
    Dim myIV As ImageView
    Dim myAngle As Int=0
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "3D rotations rule!"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
  
    myIV.Initialize("myIV")
    myIV.ContentMode = myIV.MODE_FILL
    myIV.Bitmap = LoadBitmap(File.DirAssets, "testpic.png")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    Dim WW As Int = 6*Width/8    'Just to center it with nice dimensions
    Dim HH As Int = WW
    Page1.RootPanel.addview(myIV, (Width-WW)/2, (Height-WW)/2, WW, HH)
End Sub

Private Sub Application_Background
End Sub

Sub  Page1_Click
    Dim no As NativeObject = Me
    myAngle = (myAngle+10) Mod 360
    no.RunMethod("rotateView::",Array(myIV, myAngle))
End Sub

#if OBJC
- (void)rotateView:(UIView*)mView :(NSInteger)mAngle {
    //Apply ransformation to the PLANE
    CATransform3D t = CATransform3DIdentity;
    //Add the perspective!!!
    t.m34 = 1.0/ -500;    // Play with this for depth changes
    t = CATransform3DRotate(t, mAngle * M_PI / 180.0f, 0, 1, 0);
    mView.layer.transform = t;
}
#End If
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thanks it works.
As you understand, I'm inserting 3D rotations in the B4X views of my library
I already know how to do for Android (RotateX, Pivot etc ..) I was missing the method for IOS. ;):D

but ine question... Why this?
B4X:
 myAngle = (myAngle+10) Mod 360
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
BUT if I wanted to pass more parameters?
These are stupid questions for those who know Object-C ... but it's the first time I'm dealing with this language and it's different from anything I've ever seen

B4X:
Sub  Page1_Click
    Dim no As NativeObject = Me
    no.RunMethod("rotateView::",Array(myIV, myAngleX, myAngleY, myAngleZ))
End Sub

#if OBJC
- (void)rotateView:(UIView*)mView :(NSInteger)mAngle { --- ??????????????
    //Apply ransformation to the PLANE
    CATransform3D t = CATransform3DIdentity;
    //Add the perspective!!!
    t.m34 = 1.0/ -500;    // Play with this for depth changes
    t = CATransform3DRotate(t, mAngle * M_PI / 180.0f, 0, 1, 0);
    mView.layer.transform = t;
}
#End If
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
BUT if I wanted to pass more parameters?
These are stupid questions for those who know Object-C ... but it's the first time I'm dealing with this language and it's different from anything I've ever seen

Also learning, agree that syntax scares a bit at the beginning...
B4X:
Sub  Page1_Click
    Dim no As NativeObject = Me
    'Rule: as many ":" as parameters
   ' Using here only one base-angle to make it usable in the original demo
    no.RunMethod("rotateView::::",Array(myIV, myAngle, myAngle/2, myAngle/3))
End Sub

#if OBJC
- (void)rotateView:(UIView*)mView :(NSInteger)mAngleX :(NSInteger)mAngleY :(NSInteger)mAngleZ  { 
    //Apply transformation to the PLANE
    CATransform3D t = CATransform3DIdentity;
    //Add the perspective!!!
    t.m34 = 1.0/ -500;    // Play with this for depth changes
    t = CATransform3DRotate(t, mAngleX * M_PI / 180.0f, 1, 0, 0);
    t = CATransform3DRotate(t, mAngleY * M_PI / 180.0f, 0, 1, 0);
    t = CATransform3DRotate(t, mAngleZ * M_PI / 180.0f, 0, 0, 1);
    mView.layer.transform = t;
}
#End If
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Also learning, agree that syntax scares a bit at the beginning...
B4X:
Sub  Page1_Click
    Dim no As NativeObject = Me
    'Rule: as many ":" as parameters
   ' Using here only one base-angle to make it usable in the original demo
    no.RunMethod("rotateView::::",Array(myIV, myAngle, myAngle/2, myAngle/3))
End Sub

#if OBJC
- (void)rotateView:(UIView*)mView :(NSInteger)mAngleX :(NSInteger)mAngleY :(NSInteger)mAngleZ  {
    //Apply transformation to the PLANE
    CATransform3D t = CATransform3DIdentity;
    //Add the perspective!!!
    t.m34 = 1.0/ -500;    // Play with this for depth changes
    t = CATransform3DRotate(t, mAngleX * M_PI / 180.0f, 1, 0, 0);
    t = CATransform3DRotate(t, mAngleY * M_PI / 180.0f, 0, 1, 0);
    t = CATransform3DRotate(t, mAngleZ * M_PI / 180.0f, 0, 0, 1);
    mView.layer.transform = t;
}
#End If
I tried and tried again, read tutorial. I've tried the code you mentioned ... only I did not understand what the ":" was for ... the number of parameters. :confused::confused::confused:

He signaled me an error.o_Oo_O

Thank's
 
Upvote 0
Top