Right now I have a UIImageView of a tree, with various UI elements placed on top of it. I find this kind of borring to look at. What I would like to do is to have my tree blowing in the wind.
My plan is to create my animation in Blender, and then export it as a video, and use this video in place of my background UIImageView.
A) Is it possible to use a video in such a way?
B) What type of view will I need?
C) Is it possible to loop the video?
As I haven't started making the animation yet, I am flexible and would be open to other suggestions to acheive the same effect.
Thanks!
This is one way, which have a lot of images and passing these images to the UIImageView.
You have many images and save these images in an array.
backgroundImageView.animationImages = imagesArray;//pass in the array
backgroundImageView.animationRepeatCount = 0;
backgroundImageView.animationDuration = duration;//set some time.
[backgroundImageView startAnimating];
Hope this helps.. Just a suggestion
Related
I am aware that you can set the surface of a sphere or a plane as an image by doing something like this when you first add it to the scene.
UIImage image = UIImage.FromFile("firstimage.jpg");
Sphere.FirstMaterial.Diffuse.Contents = image;
But what about when you want to update it on user action... like say on button click. Right now I do something like this.
UIImage newImage = UIImage.FromFile("secondimage.jpg");
//digs through the scnview and the scene, into it's child nodes, finds the geometry and replaces the image
mySCNView.Scene.RootNode.ChildNodes[0].Geometry.FirstMaterial.Diffuse.Contents = newImage;
But this seems kind of messy and actually takes about 2 or 3 seconds to complete. I'm not particularly worried about the array index hardcode.
Is there a more efficient way to go about this kind of update?
P.S. I apologize for some funny looking lines of code, this is actually being written in Xamarin.iOS, but feel free to answer in Swift or C and I'll do the translation.
It sounds like your bottleneck is the transfer of the image onto the GPU. So how about preloading it? Instantiate the material before you need it. Then swap it out upon user action.
I've seen many solutions out here but they're not exactly what I'm looking for. What I'm attempting to do is have the view's background to move an image multiple times-- slowly and diagonally rather than horizontally or vertically.
From a web designing perspective, this can be achieved with a tiled bg.gif where the image gives the effect of an image moving without additional programming.
Example:
However, I'm not sure whether this is achievable within Swift programming. I'm sure alternative solutions are out there like having a single image (a smiley face) tiled to fill the view frame and have it move diagonally by incrementing it's x & y coordinates.
I'm new to iOS development and Swift yet I am learning a lot! Much help will be appreciated.
refer this two links. it will help to achieve what you want. click here and click here
Update as advised in comment : download SwiftGif and Import the Gif.swift in your project and do the following:
// Returns an animated UIImage
let myGif = UIImage.gifWithName("imggif")
// Use the UIImage in your UIImageView
let imageView = UIImageView(image: myGif)
here imggif is your gif image which shown in question. put it in your project
hope this will help :)
I'm working in Xcode 6 on tiling the iPhone background with many UIImageViews and I'd like to know if this is the most efficient solution.
I know one simple solution would be to create image views in the storyboard and cover the entire screen with them manually. I'd like to do it with code. Here's the code I have currently (5x5 is an okay size since I can scale it up or down to fill the screen with bigger or larger images):
CGRect tiles[5][5];
UIImage *tileImages[5][5];
UIImageView *tileViews[5][5];
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
tiles[i][j] = CGRectMake(50*i,50*j,50,50);
tileImages[i][j] = [UIImage imageNamed:#"tile.png"];
tileViews[i][j] = [[UIImageView alloc] initWithFrame:tiles[i][j]];
tileViews[i][j].image = tileImages[i][j];
[self.view addSubview:tileViews[i][j]];
}
}
Currently all the images are the same, but in the long haul I'm going to make them dependent on various factors.
I have read around and I know that UIImageViews are finicky. Is this the proper and memory efficient way to tile a background with UIImageViews? Is there a better way to do this? Can I manually go in after the tiles are initialized and change an image it's displaying and have it update in real time with just this?
tileView[1][2].image = [UIImage imageNamed:#"anotherTile.png"];
Thanks in advance, I just finished a basic 6-week course in IOS programming at my college so I still find myself trying to appease the Objective C Gods occasionally.
I guess my doubt would be why you need them to be image views. Drawing an image in a view or layer is so easy, and arranging views or layers in a grid is so easy; what are the image views for, when you are not really using or needing any of the power of image views?
I have several apps that display tiled images - one shows 99 bottles in a grid, one shows a grid of tile "pieces" that the user taps in matched pairs to dismiss them, one shows a grid of rectangular puzzle pieces that the user slides to swap them and get them into the right order, and one shows a grid of "cards" that the user taps in triplets to match them - and in none of those cases do I use image views. In one, they are CALayers; in the other cases they are custom UIView subclasses; but in no case do I use UIImageViews.
For something as simple as a grid of images, using UIImageViews seems, as you seem to imply, overkill. If the reason you have resorted to UIImageViews is that you don't know how to make a UIView or a CALayer draw its content, I'd say, stop and learn how to do that before you go any further.
I'm building app for kids with lots of interactive image objects (click on pic & get result)
For example: I have cat on my screen and with click on it I need to produce sound.
After having read lots of info I got the idea that it's almost impossible to transform certain parts of image to clickable objects.
While there are lots of games on the app store which contains lots of custom shaped clickable objects. How did they manage to do this?
What I need read to get the answer? Thank you in advance.
UPDATE: I can have my clipart images as vector-graphic, e.g. .svg file. Will it make the situation simpler?
Implement each image as a UIButton and set the background of each button as the image desired. (setBackgroundImage)
Links:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/
Using images is one option, but if you want taps within a certain non rectangular shape, check out OBShapedButton
If you really want super accurate touches, you could construct a bezierpath in the shape of the image then use
[UIBezierPath containtsPoint:]
https://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/instm/UIBezierPath/containsPoint%3a
You could also possibly get the pixel colour underneath the touch, but that wouldn't give much room for error if the user tapped near the edge:
https://stackoverflow.com/a/7101544/78496
Frosted Glass Effect
I'm thinking of how to approach this logically..
So we take the background image ( for example )
Then, we want to add our frosted glass button to this image. Here's how it should look..
Now I know I cannot programatically blur the background image of the button, so I'll to try and do it with two images.. Background.png and Backgorund_Blurred.png.
Now, the frosted glass effect will happen on animated objects. So, as they move across the screen, it should appear that it is blurring the background image behind it, however, to achieve this I can only think of one way. But doing so is beyond my current capability.
It would have to be a background_blurred image for the UIButton for example. No scaled in any way, and the exact same size as the normal background. Then, I would have to take the buttons relative position on the normal background and append the background_blurred of the button to suit.
My first question; is this possible?
Second question; is there an easier approach?
Lastly, I've added an image to make sense of the relative position theory.
Check out the FXBlur library, it'll let you blur images/views.. I've used it successfully and sounds like it'll do what you want.
I think having two images for these assets maybe easier, but having the views blur may be better in the long run as you wouldn't have to worry about updating the images for different resolutions in the future or care about how big the button is/will be.. Also if you want to do this with more images it'll turn into a mess with all the different images to manage.. The library is simple to use, with one call you'll have a blurred image/view..