Framer Studio, iOS Messages "select text" - ios

With Framer Studio, I'm trying to replicate the iOS Messages App's "select text" feature as seen below:
Particularly, I want the zoomed in bubble to show up on any location when I press and hold.

Here is an example Chris Aga posted in the Framer.js Facebook group: http://share.framerjs.com/78aqs01eogh9/
So what you want to do is, first check for longpress:
screen.on Events.TouchStart, (event) ->
isHeld = true
Utils.delay .25, () ->
if isHeld then triggerLongHold(event)
To normalize mouse and touch event coordinates we're using the Pointer Module. So you'll need to include the module in your project.
After that move the magnifying glass layer to wherever the long press is happening:
triggerLongHold = (event) ->
mask.opacity = 1
shadow.opacity = 1
pointerValues = Pointer.screen(event, screen)
mask.x = pointerValues.x - mask.width / 2
mask.y = pointerValues.y - mask.height
bgMagnified.x = -2 * pointerValues.x + 140
bgMagnified.y = -2 * pointerValues.y + 120
and update its position if the user moves the finger/mouse:
screen.on Events.TouchMove, (event) ->
if isHeld
pointerValues = Pointer.screen(event, screen)
mask.x = pointerValues.x - mask.width / 2
mask.y = pointerValues.y - mask.height
bgMagnified.x = -2 * pointerValues.x + 140
bgMagnified.y = -2 * pointerValues.y + 120
Hope this will get you started!

Related

Garry's Mod trying to make a ring like health bar with seperators smooth

So I have a ring looking like health bar in GMod, and I'm trying to make the health bar go down smoothly as I lose health, and obviously I got no idea how to do that, I've tried math approach and lerping but it didn't work (probably my poor coding was at fault) so your suggestions with those methods are still welcome
This is the function that draws my health
local function healthBar()
local hp = ply:Health()
local maxHp = ply:GetMaxHealth()
surface.SetDrawColor(225,225,225,255)
for i = 0, 180, 45 do
function HpAng(i, maxAng)
local curSeg = (i / maxAng) + 1
local segAng = (maxHp / 5)
local segMax = segAng * curSeg
if segMax <= hp then
return i + maxAng
end
return (i + maxAng) * (hp/segMax)
end
draw.JRing(ScrW() / 2 + 750, ScrH() / 2 + 260, 75, 8, i + 2, HpAng(i, 45))
end
end
This is how the health bar looks like:
https://i.stack.imgur.com/TsKzm.jpg
math.Approach moves one value towards another value by a given increment, and so the idea is that you want to increment the health currently displayed towards whatever the player's current health is, in each frame. Assuming your healthBar() function is run inside a rendering function such as HUDPaint, this should work:
local lerpHp = 0
local lerpSpeed = 0.1
local function healthBar()
local hp = ply:Health()
local maxHp = ply:GetMaxHealth()
if (lerpHp != hp) then
lerpHp = math.Approach(lerpHp, hp, math.abs(hp - lerpHp) * lerpSpeed)
end
surface.SetDrawColor(225,225,225,255)
for i = 0, 180, 45 do
function HpAng(i, maxAng)
local curSeg = (i / maxAng) + 1
local segAng = (maxHp / 5)
local segMax = segAng * curSeg
if segMax <= lerpHp then
return i + maxAng
end
return (i + maxAng) * (lerpHp/segMax)
end
draw.JRing(ScrW() / 2 + 750, ScrH() / 2 + 260, 75, 8, i + 2, HpAng(i, 45))
end
end
The lerpHp variable is outside the function, since we need to keep track of what the old health was between frames.
math.abs(hp - lerpHp) increases the speed of the animation proportional to the difference in health, meaning the health bar will move faster if you have lost a larger amount of health. This is optional but this is the behaviour you'll see in most Garry's Mod HUDs.

Multiplication table in Swift ios

I am learning how to make a multiplication table in swift and used
override func viewDidLoad() {
let n = Int(str)!
while (i<=10) {
let st = "\(n) * \(i) = \(n * i)"
lbl.text = st
i += 1
}
this code. i have a label in which i want to show the table, but the problem is that only the last result which is say 2*10 = 20 is showing and not all the other value. i am confused what to do, please help what to do so that all the values are displayed.
Glad you've decided to learn Swift. You're on the right track, but as others have said, your final iteration of the loop is replacing the contents of lbl.text.
There are many ways to achieve what you want, but for problems like this I'd suggest starting off working in a playground rather than worrying about labels, viewDidLoad and suchlike.
Here's a nice Swift-y way to do what you want
let n = 12
let table = Array(0...10).map({"\(n) * \($0) = \(n * $0)"}).joinWithSeparator("\n")
print("\(table)")
Gives…
12 * 0 = 0
12 * 1 = 12
12 * 2 = 24
12 * 3 = 36
12 * 4 = 48
12 * 5 = 60
12 * 6 = 72
12 * 7 = 84
12 * 8 = 96
12 * 9 = 108
12 * 10 = 120
To break that down…
// Take numbers 0 to 10 and make an array
Array(0...10).
// use the map function to convert each member of the array to a string
// $0 represents each value in turn.
// The result is an array of strings
map({"\(n) * \($0) = \(n * $0)"}).
// Join all the members of your `String` array with a newline character
joinWithSeparator("\n")
Try it for yourself. In Xcode, File -> New -> Playground, and just paste in that code. Good luck!
That's because every time the loop iterates, it overwrites the previous value in label.text. You need to append the new value to existing string value in label, as suggested by RichardG.
let n = Int(str)!
while (i<=10) {
let st = "\(n) * \(i) = \(n * i)"
lbl.text = lbl.text + " " +st //Append new value to already existing value in label.text
i += 1
}
There is also a possibility of UI issue. You have to provide number of lines to the label or it will mess up the display. It also needs to be of size enough to hold your data. A better option would be UITextView which is scrollable, if you are unwilling to handle cases for label height and width. But if you want to stick with UILabel, the following code will resize the label depending on text for you:
lbl.numberOfLines = 0; //You only need to call this once. Maybe in `viewDidLoad` or Storyboard itself.
lbl.text = #"Some long long long text"; //here you set the text to label
[lbl sizeToFit]; //You must call this method after setting text to label
You can also handle that by Autolayout constraints.
Easy way to do it with SWIFT 2.0
var tableOf = 2 //Change the table you want
for index in 1...10 {
print("\(tableOf) X \(index) = \(index * tableOf)")
}
OUTPUT
repeat-while loop, performs a single pass through the loop block first before considering the loop's condition (exactly what do-while loop does).
1) repeat...while Loop
var i = Int()
repeat {
print("\(i) * \(i) = \(i * 11)")
i += 1
} while i <= 11
2) While Loop
var i = Int()
while i <= 11
{
print("\(i) * \(i) = \(i * 11)")
i += 1
}
3) For Loop
for n in 1..<11
{
print("\(n) * \(n) = \(n * 10)")
}

Fade text color in Corona SDK

I have a list of color codes and want to make a text fade the colors smoothly like in this picture:
Is this possible with Corona? I couldn't find a way to do this yet.
Try this function I made, might not be perfect but it works for me:
-- Transitions a display object from one color to another (based on 0 to 1 values)
function applyColorTransition(oDisplayObject, nDelay, nStartR, nEndR, nStartG, nEndG, nStartB, nEndB)
if oDisplayObject.setFillColor then
local nIterations = 10
local nStepsR = (nEndR - nStartR) / nIterations
local nStepsG = (nEndG - nStartG) / nIterations
local nStepsB = (nEndB - nStartB) / nIterations
local nI = 1
timer.performWithDelay( nDelay, function()
oDisplayObject:setFillColor(nStartR + nStepsR * nI, nStartG + nStepsG * nI, nStartB + nStepsB * nI)
nI = nI + 1
end, nIterations)
end
end

Creating highstock zoom-in/out button

I have the following problem - I'm trying to create highstock graphic with zoom-in/zoom-out buttons, but something is wrong with the zooming. When i press the button most of the times the chart zooms to the correct time interval, however, after I press the button a couple more times, the chart starts to behave weird - the animations aren't correct or it doesn't zoom or it zooms to the wrong interval.
This is the zooming function:
var xAxis = graphic.xAxis[0];
var minimum = xAxis.dataMin;
var maximum = xAxis.dataMax;
var newMin = 0;
var newMax = 0;
//when zooming out
newMin = xAxis.min - 360000;
newMax = xAxis.max + 360000;
//when zooming in
//newMin = xAxis.min - 360000;
//newMax = xAxis.max + 360000;
if (newMin < minimum)
newMin = minimum;
if (newMax > maximum)
newMax = maximum;
if (newMin > newMax) {
alert("min bigger than max");
}
console.log("newMin: " + newMin + " newMax: " + newMax);
xAxis.setExtremes(newMin, newMax);
Here's a fiddle: http://jsfiddle.net/E5kth/3/
jquery - 1.6.4
jquery mousewheel - 3.1.6
highstock - 1.3.7
Thanks in advance ;]
EDIT:
Here is a NEW video with better explanations of the problem: https://www.dropbox.com/s/5x1k5b0lbtqw81u/highstock_ordinal-false_bug_converted.avi
for better quality - download the video, dropbox streaming is with low quality.
I prepared simple example how it should be done, http://jsfiddle.net/3vB5B/. It get range from chart and then reduce range on 24 hours.
$('#btn').click(function(){
var min = chart.xAxis[0].getExtremes().min,
max = chart.xAxis[0].getExtremes().max;
chart.xAxis[0].setExtremes((min + 12 * 3600 * 1000),(max - 12 * 3600 * 1000)); //12 hrs on min and 12hrs on max, summarised it is one day.
});

Drop Down animation for Image on Tap

I have a image declared at some specific location.
local deselectButton = display.newImage ( "images/nutritional info/deselectButton.png" )
deselectButton.x = display.contentWidth / 2 - 15
deselectButton.y = display.contentHeight / 2 - 172
deselectButton.id = "0"
nutriinfo:insert(nutriNavBar)
When I tap on that image, I want another image to be displayed. That is, this second image should fade in and out every time I click on the above image.
local dropDown1 = display.newImage ( "images/nutritional info/dropDown.png" )
dropDown1.x = display.contentWidth / 2 - 75
dropDown1.y = display.contentHeight / 2 - 65
dropDown1:setReferencePoint(display.TopCenterReferencePoint)
After your code, just do as follows... This may help you:
local function addListener()
deselectButton:addEventListener("tap",clickFunction)
end
local clickCount = 0
function clickFunction()
deselectButton:removeEventListener("tap",clickFunction)
clickCount = clickCount + 1
if(clickCount%2==1)then
-- show the image
transition.to(dropDown1,{time=200,x=dropDown1.x,y=dropDown1.y+100,alpha=1,onComplete=addListener}) -- or parameters as you like
else
-- hide the image
transition.to(dropDown1,{time=200,x=dropDown1.x,y=dropDown1.y-100,alpha=0,onComplete=addListener})
end
end
deselectButton:addEventListener("tap",clickFunction)
Note: The above code provides you both drop down as well as fade-in/out effect. But, if you need fade in and fade out effect only, you can eliminate y parameter from transition, and if you want the drop down type effect, you can eliminate the alpha parameter.
Keep coding............... :)

Resources