iOS Question [Solved] Draggable view inside another

angel_

Well-Known Member
Licensed User
Longtime User
I'm using this example:


Is it posible to have a draggable button inside a draggable panel?

I'm trying with this code but it doesn't work:

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    
    pnl.Initialize("")
    Page1.RootPanel.AddView(pnl, 0, 0, 300, 300)
    pnl.Color = Colors.Yellow
    
    Dim dv1 As DraggableView
    dv1.Initialize(Page1.RootPanel, pnl)
    
    button1.Initialize("", button1.STYLE_SYSTEM)
    pnl.AddView(button1, 0, 0, 100, 100)
    button1.Color = Colors.ARGB(100, 0, 100, 0)
    
    Dim dv2 As DraggableView
    dv2.Initialize(pnl, button1)
End Sub
 

Attachments

  • Draggable_View.zip
    2.6 KB · Views: 136

Semen Matusovskiy

Well-Known Member
Licensed User
Possible. In attached sample you can drag a panel and it's childs.
The way, which I used, works for UIControl only. Meanwhile not all visual components support this interface. For example, B4i Panel and Label (unlike Button) do not support.
 

Attachments

  • s25.zip
    3.4 KB · Views: 145
Last edited:
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
It works really well, but I can't implement it. I want to put the code inside a class but I get this error

B4X:
no visible @interface for 'b4i_MyClass' declares the selector '_viewtouch::::'

I did something like this

InMyClass:
Public Sub Initialize (Callback As Object, EventName As String)    
'...
innerView.Initialize("")
B4XPages.MainPage.pnlMain.AddView(innerView, xBase.Left, xBase.Top, xBase.Width, xBase.Height)

Dim noMe As NativeObject = B4XPages.GetNativeParent(B4XPages.MainPage)
noMe.RunMethod ("addDragEvents:", Array (innerView))
End Sub

Public Sub ViewTouch (action As Int, v As View, x As Float, y As Float)
'the same
End Sub

#IF OBJC
'the same 
#End If
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I don't understand, for which purpose you need a class.

Probably there is a reason to create CustomView such as DragableButton, DragablePanel etc., which will support all features of Button/Panel and additional property, for example, dragEnabled = True / False. It's enough simple, but a code will be relatively large, because it's nessesary to duplicate methods and events.
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
I don't understand, for which purpose you need a class.

Probably there is a reason to create CustomView such as DragableButton, DragablePanel etc., which will support all features of Button/Panel and additional property, for example, dragEnabled = True / False. It's enough simple, but a code will be relatively large, because it's nessesary to duplicate methods and events.
I have a main panel with several customviews inside this custom view I have panels, imageview and label, I want to move main panel with all customviews and also I want to move each customview independently
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
It was easier than I thought, without your example it would not have been possible, thank you
 

Attachments

  • Draggable_View1.zip
    2.9 KB · Views: 152
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
To use transparent panel over real view is a good idea in some situations. But you will not receive Buton1_Click etc.
I'm having trouble displaying a page with SwiftButton, does not responde, if I use native button it works

Is it related to this?

Maybe I should open a new thread
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Theoretically custom views could be a problem. But I don't see any problem with SwiftButton. Try attached sample. You can see events in the log.
 

Attachments

  • DraggableView.zip
    170.6 KB · Views: 145
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Thank you, you're right, there was no problem with the code .

The problem is what Eres said in this thread:

I was loading the layout with buttons inside a customlistview, and was missing the event click. I attach the solution that Erel said.
 

Attachments

  • DraggableView2.zip
    173.7 KB · Views: 156
Upvote 0
Top