I have a working textfield in corona...I instantiated it using:
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
nameTextField:addEventListener( "userInput", textListener )
I then made sure to add this to the scene's self.view in the create method:
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
The whole scene is shown using a showoverlay method.
composer.showOverlay( "renameoverlay", options )
When I hide the scene using hide overlay:
composer.hideOverlay( "fade", 400 )
Even after hiding the whole scene using the above code, the nameTextField still gets left on the screen.
This doesn't happen inside my other scenes.
What could be causing this????
How do I solve this???
First, native.newTextField()'s can be added to display.newGroup()'s. The will move with groups, but they still sit on top of the display hierarchy. Scene's that use fade or crossFade can't hide the text fields because they are not being moved.
Since it looks like your overlay is using "fade", you will need to hide the text fields when you call showOverlay and show them when you're done with the overlay.
Scope matters too. I can't tell what part of your code you're creating the new text field, but it has to be visible to any place you are referencing it.
It seems that native objects can't be added to dispaly groups , you need to remove the native object when you hide the scene, try this:
add scene:hide(event)
function scene:hide(event)
if nameTextField then
nameTextField :removeSelf()
nameTextField = nil
end
end
scene:addEventListener("hide", scene)
Hope this helps you!
I am fairly sure it is because of access issue for the local variable.
Change this
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
to this
nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
or this
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
to this
function scene:create( event )
sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
Related
I have a UITextField above a Google Maps View (GMSView). When I tap on the Textfield it does not become the first responder, neither do any of the delegate or action events work (Delegate Event like textFieldShouldBeginEditing and Action Events like .allEditingEvents).
The only way the Textfield is becoming the first responder is by hardcoding it in with
tf.becomeFirstResponder()
But when I tap on it nothing happens.
The Action Touch events like .touchUpInside etc. do work normally on the TextField, so I know the frame is ok.
I am creating and adding the TextView like this:
tf = UITextField(frame: CGRect(x: 100, y: 200, width: 300, height: 50))
tf.backgroundColor = .white
tf.placeholder = "sdfdsf"
tf.translatesAutoresizingMaskIntoConstraints = false
tf.addTarget(self, action: #selector(self.tapped), for: .touchUpInside)
self.mapView.addSubview(tf)
tf.centerXAnchor.constraint(equalTo: mapView.centerXAnchor).isActive = true
tf.centerYAnchor.constraint(equalTo: mapView.centerYAnchor).isActive = true
tf.widthAnchor.constraint(equalToConstant: 300).isActive = true
tf.heightAnchor.constraint(equalToConstant: 50).isActive = true
If you have any idea why this happens (or in this case does not happen) please leave a comment or an answer. I have worked on this for over 2 days straight now.
UPDATE:
I actually added the textfield to the Mapview itself. The Mapview
kinda does something strange with the layering of the view and messes
up the view of the TextView.
The solution was to add the TextView to the main view and not to the
MapView subview.
So it's (from back to front layer):
ViewController
(Main) View
Google Maps view
View
TextField
This works
Please try this:
self.mapView.bringSubviewToFront(tf) // Add this line below "self.mapView.addSubview(tf)"
This will ensure that the tf(TextField is on Top and Tappable)
Did you assigne delegate to text field like :-
tf. delegate = self
If you want to bring a subview to the front, you can use:
self.view.bringSubviewToFront(tf)
I'm working with kgPanels to create a raid marker utility. I have two panels. One panel functions as a button - we'll call it rmButton. When rmButton is pressed it opens up the raid marker utility - rmUtility.
In kgPanels you create a panel on which you can add scripts that go in a number of different handlers. For rmUtility I am using OnLoad and OnEvent.
Right now everything is working as far as placing markers on targets. I would like to add further functionality that would allow placing world markers when either shift button is held. I'm having trouble getting that integrated.
In my OnLoad script:
local btnWidth = 30 -- the width of each button
local btnHeight = 30 -- the height of each button
local leftBorderOffset = 7 -- from the left border of the kgPanel to the first button
local btnOffset = 7 -- pixels between the buttons
local topBorderOffset = -7
self:RegisterEvent ("PLAYER_REGEN_DISABLED")
self:RegisterEvent ("PLAYER_REGEN_ENABLED")
self:Show()
self.buttons = {}
local hideFunc = function(s) s.parent:Hide() end
for n=1,6 do
local btn = CreateFrame("Button",nil,self,"SecureActionButtonTemplate")
btn:SetSize(btnWidth, btnHeight) -- replace this
btn:SetPoint("TOP",0,topBorderOffset - ((n-1) * (btnHeight + btnOffset)))
btn:SetAttribute("type","macro")
btn:RegisterForClicks("AnyUp")
btn.parent = self
btn:SetScript("PostClick",hideFunc)
btn:RegisterEvent ("MODIFIER_STATE_CHANGED")
if (event == "MODIFIER_STATE_CHANGED") then
if n == 6 then
btn:SetAttribute("macrotext","/cwm all")
else
btn:SetAttribute("macrotext",("/wm %d"):format(n))
end
else
if n == 6 then
btn:SetAttribute("macrotext","/tm 0")
else
btn:SetAttribute("macrotext",("/tm %d"):format(n))
end
end
self.buttons[n] = btn
end
self.buttons[1]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Square.tga")
self.buttons[2]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Triangle.tga")
self.buttons[3]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Diamond.tga")
self.buttons[4]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Cross.tga")
self.buttons[5]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Star.tga")
self.buttons[6]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Clear.tga")
In my OnEvent script:
if event == "PLAYER_REGEN_DISABLED" then
self:Hide()
elseif event == "PLAYER_REGEN_ENABLED" then
self:Hide()
end
When this panel loads it makes six buttons - five with raid markers, and one that clears the markers. When a button is pressed the panel will hide, and the panel will automatically hide when I enter combat.
As mentioned, I need the panel to accept a 'shift' modifier key to place the world marker.
Thanks.
Did you try something like
btn:SetAttribute("shift-macrotext1",("/wm %d"):format(n))
https://wow.gamepedia.com/SecureActionButtonTemplate#Modified_attributes
Unless you mean you want to use Shift to place a world marker? Instead of using it as a modifier for your secure action button? I'm not aware of any modifier keys like shift, ctrl, alt being able to activate an action button.
I'm creating a basic sketching app using swift 1.2 and Xcode 6.4. The feature I'm working on is adding text to the image for future manipulation.
So far I have the text the user enters adding to the drawing via label, but it is being placed (I assume) behind the UIImage that is to be drawn upon. This is preventing the associated tap gesture from being recognised. The label is also obscured when drawn over.
How do I place the label on top of everything else to prevent it being drawn over? The end goal is to allow the user to move the label.
If I was using my usual web stack I'd set the z-index of the element to a high value via CSS.
Edit: Using view.bringSubviewToFront(label) prevents the text from being drawn over, but does not allow the tap gesture to be picked up.
Heres my code:
func printText(){
println(textString)
var label = UILabel(frame: CGRectMake(5, 100, 200, 50 ))
label.textAlignment = NSTextAlignment.Center
label.text = textString;
let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap"))
label.addGestureRecognizer(tap)
self.view.addSubview(label);
}
func handleTap() {
print("tap working")
}
Any help much appreciated.
If you want z-index use:
label.layer.zPosition = 1;
Also you could play with bringToFront method on the parent view:
self.view.bringSubviewToFront(label);
You can check that function here :
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/
Also, you should add the following:
label.userInteractionEnabled = true
to enable touches.
Try using those in the parent view:
view.bringSubviewToFront(label)
view.sendSubviewToBack(imageView)
It all depends on what you can, or want to do.
You can call label to front by
self.view.bringSubviewToFront(label)
or
You can send image view to the back by
self.view.sendSubviewToBack(imageView)
i need some help,
im making an app in corona sdk which contains 4 scenes, main, list, tab1, tab2, the main scene takes you to the list scene by a button and the List takes you to tab1 and tab1 takes you to tab2, what im trying to do is make tab2 go back to the scene List by pressing a button, and when i press on the button nothing happens!!
local button1 = widget.newButton
{
left= 250,
top= 650,
defaultFile = "red1.png",
label = "select chapter",
font = "Arial",
fontSize = 34,
onEvent = handleButtonEvent,
onPress = function() storyboard.gotoScene( "list" ); end,
selected = true
}
You appear to be using a function to handle the event of the botton with "onEvent = handleButtonEvent"
You should instead use that function to do the transition:
-- Function to handle the press of the button
local function handleButtonEvent(event)
if ( "ended" == event.phase) then
storyboard.gotoScene("list")
end
end
and
-- Creation of the button
local button1 = widget.newButton
{
-- All your variables here
onEvent = handleButtonEvent,
}
and you might even be looking for something like this; this function will instead take the user back to the previous scene.
-- Function to handle the press of the button
local function handleButtonEvent(event)
if ( "ended" == event.phase) then
storyboard.gotoScene(storyboard.getPrevious())
end
end
On-Off Switch - widget.newSwitch() doesn't work when I "move" the switch, it works only when I press.
I've tried setting "onEvent" but looks like it's completely ignored as nothing happens.
local widget = require( "widget" )
-- Handle press events for the checkbox
local function onSwitchPress( event )
local switch = event.target
print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) )
end
-- Create the widget
local onOffSwitch = widget.newSwitch
{
left = 250,
top = 200,
style = "onOff",
id = "onOffSwitch",
onPress = onSwitchPress
}
The On-Off switch widget has two states: onPress and onRelease.
OnPress is called when we touch the switch. OnRelease is called when we release the switch. There is no event like onMove. This is why you cannot tap the move event.
See the link for more details.