Hi I'm working with swift to create a game and I'm facing a problem.
I'm trying to have 20 images than I can simply control with a number (1,2,3,4,5...20)
I would have, for example, a for statement in which I would put a command to place the picture in the middle of the screen.
Let's clarify everything: it's buildup a game in which the user will need to tap a certain picture on the screen and, depending of the image, a certain action will occur.
I simply don't want to create 20 individual image view with 20 variable to define the type of the image. I would like to have an IbAction(for the button on top of the image) that will trigger a series of action depending on the image that has been touch and the type of picture that is in it.
I can build my game in simple Swift or use SpriteKit.
thanks!
One way is to:
Place all your images as the background image in buttons.
Give each one a unique tag in the attributes inspector
Connect all the buttons to the same IBAction
Use a switch statement to drive control flow
Example:
class ViewController: UIViewController {
#IBAction func imageSelected(sender: AnyObject) {
switch sender.tag {
case 1:
println(sender.tag)
case 2:
println(sender.tag)
default:
break
}
}
}
Related
I want to build a website with React on which you can select different parts of a body. I would like to ask for your opinion what would be the best possibility for that? How can I highlight different parts of the body and make them clickable?
I would image a screen like this where I can press e.g. an arm, leg, head etc.:
Thank you for your help!
You will need two images.
Original colour body shape ( let's call this passive state ).
Active colour body shape.
Create a grid of rectangles on top of passive state image according to body parts, slice the active body shape image and put in rectangles as background images and set the image size to 0. On hover just set the size of the image to the original value.
I have an Image (map of Africa). I want each countries to be clickable such that a new form is opened on tap. Is this possible with CN1?
I have checked the cn1libs portal and can't find any library that does this.
I thank you
Create two maps. One would look like you want the map to look on the screen. The other would use a different color for every country.
Use a pointer listener or pointerReleased on a focusable component to track user taps on the map so you'd have an X/Y coordinate.
Use getRGB() to get the RGB colors of the pixels in the color map, then get the color at rgb[x + y * imageWidth]
This color represents the country that was picked and you can map to that using a switch statement.
I have developed app using Codename one.I want to set specific height of dialog because my text overidden while displaying message in dialog body .what should I do for that?
Thanks in Advance?
I have added image in which first image is original image and second one is cut image which is displaying on screen while using infinite progress bar. my code is "Dialog ipDialog = new InfiniteProgress().showInifiniteBlocking(); ipDialog.Dispose()" I want whole image on screen like original image.
can you help me to solved this ?
You can use the Dialog show method that accepts int values to determine the distance from the edges. But normally this is a matter of the text sizing and dialog construction.
Also make sure you are showing the Dialog from the EDT thread.
I have a big image with coordinate points.
I need to navigate through these points by pressing onscreen buttons.
Only a part of image is seen on the screen at once (shows your location).
By pressing arrow button the view moves to the next part of the same image.
This example looks good.
Please, suggest any way to implement this functionality in Codename One App
Thank You.
You can use the Map component but you can place any image as a label icon within a scrollable container and just let the user use the touch/keys to scroll.
I want to display a modal view but I have two problems:
There is no presentModalViewController in iOS 6 and I have to use presentViewController which is just display my second ViewController like a modal segue not a modal window without full screen option,
My second problem is how can I show the modal window from UICollectionViewController. I tried to use presentViewController but it just works with ViewController not CollectionViewController.
The best example of what I want to do is this (Instagram). How they made this modal window? Is it because it's still working with older iOS versions and it's not iOS 6 yet? Or there is another way to display modal window like this from UICollectionViewController?
Thanks
If I understood you correctly what you are trying to achieve is to present one of your ViewControllers over the parent and still see the parent ViewController in the background.
First solution:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext; //self.modalPresentationStyle might do a better job here
[self presentViewController:vc animated:NO completion:nil];
Make sure your SecondViewController content is smaller than your current ``ViewController` and that you can see the background color of it in StoryBoard \ xib. The background color will be clear and will create the transparency effect.
Second Solution:
Create a Container (iOS 6 and up if you are planning to use the Storyboard IB, lower than that will let you create Containers but only progrematicly).
Set the container size 3/4 of the parent size and connect the second viewcontroller to it. Instead of segueing \ pushing to your second viewcontroller you can just
myContainer.alpha = 1;
to show it on screen.
I would take a look at the docs for UIContainerView which is used for displaying a view controller as a child of another view controller in a similar way to a non-fullscreen modal presentation.
As you are saying that presentViewController is only works with UIViewController not UICollectionViewController.
Then simply import UIViewController class in header file of CollectionViewController as displayed below:
#import <UIKit/UIKit.h>
#class UIViewController;
#interface MyCVController : UICollectionViewController
#end