UI Image View Animations When Using ScrollView - animation

I am currently working on a project where I have a scroll view and four different screens. I have used a simple UIImage(named:"")!, code to put the frames of images into my imageView and animate the image.
I am having a problem where when I slide to my next screen the animation has already been completed. I do not know how to make it so that when I slide to the next screen the animation will then begin.
Here is the code for the animal animation
imageView.animationDuration = 1
imageView.animationRepeatCount = 1
imageView.animationImages =
[
UIImage(named:"Deer_00014")!,
UIImage(named:"Deer_00015")!,
UIImage(named:"Deer_00016")!,
UIImage(named:"Deer_00017")!,
UIImage(named:"Deer_00018")!,
UIImage(named:"Deer_00019")!,
UIImage(named:"Deer_00020")!,
UIImage(named:"Deer_00021")!,
UIImage(named:"Deer_00022")!,
UIImage(named:"Deer_00023")!,
UIImage(named:"Deer_00024")!,
UIImage(named:"Deer_00025")!,
UIImage(named:"Deer_00026")!,
UIImage(named:"Deer_00027")!,
UIImage(named:"Deer_00028")!,
UIImage(named:"Deer_00029")!,
UIImage(named:"Deer_00030")!,
UIImage(named:"Deer_00031")!,
UIImage(named:"Deer_00032")!,
UIImage(named:"Deer_00033")!,
UIImage(named:"Deer_00034")!,
UIImage(named:"Deer_00035")!,
]
self.imageView.image = UIImage(named: "Deer_00035")
imageView.startAnimating()

Just remove this line
self.imageView.image = UIImage(named: "Deer_00035")
Basically here you are setting the image to the ímageview' overwriting animation.

Related

Swift sender tint color

I'm working on a tic tac toe game where each square is its own button and the image of the button changes when the square is tapped. I have done this by connecting all of the square buttons to the same IBAction #IBAction func buttonPressed(sender: AnyObject) and by using sender.setImage() to change the image. The problem is, the images are all blue. I can change this blue to a different color by changing the global tint color, but what I really want is for the O and X images to be different colors. sender.tintColor throws an error and button.tintColor, as I have in the code below, just changes the color of one image back and forth every time a square is tapped. I have tried setting the global tint to no color in the File Inspector, but it just goes back to the default blue. Any thoughts?
if activePlayer == 1 {
sender.setImage(UIImage(named: "o-img"), forState: .Normal)
activePlayer = 2
button.tintColor = UIColor.blackColor()
} else {
sender.setImage(UIImage(named: "x-img"), forState: .Normal)
activePlayer = 1
button.tintColor = UIColor.whiteColor()
}
When you drag the image to the view controller's code to connect, before clicking "Ok" change the sender to UIImage instead of AnyObject.
You need to disable the button so the next player can not tap on it.
sender.enabled = false
As it turns out, changing the button type from 'System' to 'Custom' removes the tint. Hope that helps someone else who came across the same issue!

UIPopoverPresentationController's background broken?

Since iOS 9 I got a problem with the background of the UIPopoverPresentationController. It seems the shape and color are broken.
In the code below I define a popover in the prepareForSegue function and I set its preferred content size and background color. The size is shown correctly but with some mistakes in the shape of the background view. Also the color is not set (the arrow and the broken shape are white instead of dark gray (picture)). In iOS 8 it has worked as expected.
The subclassing of the UIPopoverBackgroundView should be the last option, because I just want to change the color of it, nothing else.
Any ideas?
let vc = segue.destinationViewController as! StatisticSettings_TVC
vc.preferredContentSize = CGSizeMake(300.0, 400.0)
vc.view.backgroundColor = app.COLOR_STAT_LEGEND_BACKGROUND
if let ppc = vc.popoverPresentationController {
ppc.delegate = self
ppc.backgroundColor = app.COLOR_STAT_LEGEND_BACKGROUND
}

ObjectAnimator in Android doesn't update the View's parent

Objective:
Build a SlideUp animation in a ImageView with fixed height that is placed in a LinearLayout with wrap_content height.
Problem:
The animation runs normally, but the parent LinearLayout doesn't resize itself while or after the animation occurs. I mean, if it is set to "wrap_content" and the "content" changes it's position (y axis to -100), it's expected that the parent accompanies the animation, "animating" it's height to 0 as well, or not?
How can I force it to continue "wraping" the content while the animation runs?
PS: No, it's not about fillAfter, I'm using ObjectAnimator, which changes the real object properties, not only the View drawn. For instance, the click event is not being triggered on the place the image used to be before the animation.
My code:
ObjectAnimator oa = ObjectAnimator.ofFloat(findViewById(R.id.menu_tile_image), "y", 0, -100);
Layout structure:
LinearLayout (match_parent, wrap_content) > ImageView (fill_parent, 100)
Any clue on that? Thanks!

SCNView Re-sizing Issue

I am trying to render 3D bar chart in SCNView using ScreenKit framework.
My rendering code is,
int height=10,y=0,x=0;
for (int i=0; i<10; i++) {
SCNBox *box1 = [SCNBox boxWithWidth:4 height:height length:2 chamferRadius:0];
boxNode1 = [SCNNode nodeWithGeometry:box1];
boxNode1.position = SCNVector3Make(x, y, 0);
SCNMaterial *material = [SCNMaterial material];
material.diffuse.contents = (NSColor *)[self.colorArray objectAtIndex:i%6];
material.specular.contents = [NSColor whiteColor];
material.shininess = 1.0;
box1.materials = #[material];
//boxNode1.transform = rot;
[scene.rootNode addChildNode:boxNode1];
x+=6;
height+=10;
y += 5 ;
}
I can render but while re-sizing the view the chart bars goes to the center of the view.
I need to render the chart, which cover the margins of the view and when Re-size it have to change accordingly. The image(s) below shows my problem.
Original Image:
Image where less stretching of both windows:
Can anyone please help me to fix the issue.
The the windows in the image that you had linked to in your original question was very stretched and that made it very hard to see what was going on. When I took that image and made the windows less stretched it was easier to have some idea of what is going on.
I think that you are seeing a general resizing issue. Either you are using springs and struts and have configured flexible margins on the left and right or you are using auto layout with a centered view with fixed width.
I assume that the red boxes that I have drawn in the image below is the bounds of your scene view in both these cases. You can easily see if this is the case by giving the scene view a different background color and resize it again.
My solution to your problem would be to change how your view resizes as the window resizes, to better meet your expectations.

Scrolling Background

I'm trying out new things for a simple game in Portrait mode, I want to add a seamless scrolling background to a game, the image is 512x512px.
The Main scrolling I want to have is Vertically, but I want to be able to scroll sideways too within the bounds of the image size. How should I go about with this, I'm using cocos2d.
David
Try repeating the texture (in this case within 2000px)
CGRect repeatRect = CGRectMake(0, 0, 2000, 2000);
CCSprite *background = [CCSprite spriteWithFile:#"Background.png" rect:repeatRect];
ccTexParams params =
{
GL_NEAREST,
GL_NEAREST_MIPMAP_LINEAR,
GL_REPEAT,
GL_REPEAT
};
[background.texture setTexParameters:&params];

Resources