How to create a "spinning" effect of a column of number images - ios

I am using Xcode 6 and coding in Swift. I am relatively new to Swift but have programming experience in C.
I am creating a column of random numbers which I display by programmatically creating image views with the appropriate number image.
My logic is as follows:
User presses a "spin" button
A function is called which creates a column of random numbers (ex: say 5 numbers) and displays the appropriate number image for each.
Instead of just generating my 5 numbers, displaying them and leaving the function, I put this in a loop that will process 100 times.
The purpose of the loop is to create a "spinning" effect.
This is where my problem arises. I do not get a spinning effect, instead I simply see the last 5 generated numbers that were displayed.
As best as I can tell with my limited understanding of when things occur, it seems as though the images don't actually update until the function (which was called by the user tapping a button) completes and returns.
Is this true?
If so how can I create my "spinning" effect?
How can I get the numbers to display at the time I generate and assign my number image?
This is the first time I've used this forum (as far as asking a question) and apologize in advance for anything I've done wrong when laying out my question.
Thank you - Ed

Related

How can I replicate the "Spoiler" function that most forums have, on to a Spreadsheet?

This is one of the rare cases where I don't care how or where, I just want to be able to do this. By that I mean it can be either on Google Sheets or Online Excel (because I don't have the MS Suite, I would prefer GSheets since every time I search for help on Excel, I get solutions for the Program version that uses features not in the Online one)
Basically, I want to re-create the web page of a forum... but on a spreadsheet. The reason for that is because I want to create a catalog of sorts that is related to that forum, without being restricted to the forum and to be more organized. Since I only care about the body, I just took a screenshot and essential cut a hole where the "body text" is (ideally I would like all the buttons to be images you can click and would take you the actual forum, but I'm not concerned now).
Right now, what I want to do is to preferable create a button that can hide/show text like a Spoiler button. And I don't mean the type that changes the text color to be the same as the background making it unreadable, I mean the ability to collapse/expand the text.
My current solution is using Google Sheets and I'm grouping rows and using the +/- button on the left side. That has worked pretty well so far but it has 2 glaring issues:
#1 The +/- button is all the way to the left side
#2 And that button is inaccessible to people that have "viewing only" rights to the sheet, making this kind of a pain to use for people.
For #1 I have created a "drawing" that's just a straight line going all the way to the button to the side.
And for #2, because I want to make this sheet as dumbproof as possible, I'll have to write that they'll have to duplicate the sheet in order to use it. Which is going to take me a couple of days until I make a dumbproof "guide" on how to do that.
Ultimately, currently the best solution would be to create "buttons" where each one can collapse/expand a specific grouping of rows. But even just to create buttons I have to learn scripts, which I don't know how to... I don't even know where you're supposed to write the scripts to begin with.
Currently I'm pretty satisfied with what I've made so I'm not too pressed if I don't find a better solution. No you can't look at it because it's pretty sensitive.

Swift swipe through photos randomly

Originally I had a different post, just wanted to redo it to clean it up.
This is more or less the layout I wanted to go with. Imagine the first imageview had dog pictures, the second one had cat pictures and the third one had rabbit pictures. three folders contain a group of three separate sets of pictures.
What is the best way to set it up so I can randomly swipe, lets say the first image view where it would only show pictures of dogs.
What I am asking is, is there a certain way to create the file structures or link the pictures to each image view?
I have the basics of the random (something with a 4 in it don't remember the method exactly) and the basics of swipe, just was looking for help with linking the photos and file structure.
Please let me know if this still doesn't make sense.
Thank you
EDIT
after messing with this this is where I am at:
with a very simple array basically
catsArray: [String] = ["catpic1","catpic2"......]
then I have it set up as
let randomIndex = Int(arc4random_uniform(UInt32(catArray.count)))
if (sender.direction == .Right)
{
self.catImageView.image = UIImage(named: catArray[randomIndex])
}
just me hacking things off the internet. now I am running into an issue. after a few swipes I get a null images or its just blank. Why is that?
now that I have some of this set up I am debating if I should just use parse for a server or if there is a better way.
thanks
Either approach will work. It's probably a good exercise to write both versions. You'd learn from it.
Your question is far too vague. Are you worried about memory? If so, you should not load the images into an array. Instead load the image names, and load each image as it is swiped on-screen. You might want to load the current image and the next image so it's already in memory and can be displayed without lag.
Are you talking about using a UIPageViewController? That's a good class for managing a set of pages that you can scroll through. There is a sample app from Apple called PhotoScroller that illustrates that technique, along with tiling the images so you can display large images and handle zooming and panning. (The app is written in Objective-C however.)
EDIT:
Your updates make your question a little clearer.
There are lots of ways to handle this. Here's 1.
Create 3 separate folders, one for cats, one for dogs, and one for rabbits. (in your app's documents directory, or in the bundle, if the images will be shipped with the app.)
Use NSFileManager to create 3 separate arrays of filenames. Take a look at the methods contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error: and contentsOfDirectoryAtPath:error:. You should be able to make either of those work.
Then you'll need to scramble your arrays of filenames to create a randomized order. You can use one of the block-based sort methods where your block uses a random number to determine the sort order of each pair of objects.
Finally you'll need to implement the swipe to switch.
It sounds like you are beginner so this is a lot to work through. You should break the problem into pieces and tackle them one at a time.

how to implement the same pattern

I'm new to ios, and I've already got my design ready, now I don't know is there a best practice for me to do the following thing:
I have 1000 cards, each of it is like this:
And when I slide right, it will get the next one, I slide left it will back to the previous one
I can implement this now, but I can only implement this one by one for 1000 times.
In addition, when I click the middle of the card, it will flip horizontally, then show the translation. it's the second kind of card with different language and color.
So is there any hint for me? any loop can do it?
update
About data-drive, so I thought about database, and I search the google that there's four way of persistence in ios,
I decide to choose sqlite, is it a wise choice?
Reason:
I'm familiar with mysql, and use sqlite in rails before
sqlite is not too big.
I need to save original sentence, translate sentence, saved or not flag, additional story.

how to make a view appear only if is the first time? [duplicate]

This question already has answers here:
Show screen on first launch only in iOS
(8 answers)
Closed 9 years ago.
Thanks in advance .
I wanna make a view appear only if the application is launch for the first time, I have work with a similar code to display Alerts, but I can find a way to make it with a Storyboard view ? For example my idea is : in the image below I have 7 buttons so I want the user to select which Country/Button they wanna use after this first time launch (it will be a button where they can change it back ) and how can I save the value of the button (the one that the user choose) so that every time the app launches again it goes straight to the one they selected when the app was installed ?
Thank you .
There are two pretty easy solutions I can think of.
First, in both instances, you'll be duplicating much of the same logic you say you've used previously in displaying a UIAlertView.
Option 1: Have the view with buttons that should only be displayed once as the first view. In the viewDidLoad method, check whether the app has been launched before and a button has been selected. If a button has been selected before, just go ahead and perform the segue straight from the viewDidLoad into the rest of the app.
Option 2: This time, instead of starting with the 1-time view, start with the standard first view. Check if the app has been launched before or not, and if it has, perform a modal segue into the view where they select a button (otherwise just don't perform the segue).
I'm certain there's a more elegant solution to get this work in a better way, but this is a pretty simple implementation that should be quite easy to get working.
I would us an NSUserDefault here. First check for the presence of a preference for the key you specify. If it doesn't exist you'll want to show the region selection view. If it does exist just use the region stored in the preference.
This way, if the preference every gets deleted or lost, the logic will be small enough that the user can recover fairly quickly.

I'd like to make it possible, when user reaches the last image to show the first one after it and so on

I've got an UIScrollView and in it different images (about 30). I'd like to make it possible, when user reaches the last image to show the first one after it and so on. And I want to implement the same feature with the first image (to go to the last one). I'd like to loop the images smoothly that user won't even notice that he is making another loop.
Here's an article on how to do it. It describe how and also include code - even if it's in Objective-C (but it should be easy to convert to C#).

Resources