Rotation makes UIImageView moves up -iOS - ios

I am using the following code to rotate my image view and it is working fine..but whenever I change the view and go back. my image view moves up and eventually goes off the screen.. Any ideas why? Thanks..
self.anchorImage.layer.anchorPoint = CGPointMake(1.0,0.0);
CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(1);
[self.imageView setTransform:cgaRotateHr];

Related

How to move UIimageView over another UIImageView

I am moving most of UIImageViews on view and keeping an UIImageview fixed. Everything is happening fine but problem is when moving imageviews are containing or intersecting the fixed imageview, they are just moving from under fixed imageview.
How to make UIImageviews to move over the fixed imageview.
Please Find the function StartMoving code which makes UIImageviews to move in screen and called on buttonClick event.
In code...
CGPoint pos1,Pos2,pos3;
UIImageView *ball1,*ball2,*ball3,*fixedball;
-(void)StartMoving
{
pos1=CGPointMake(5.0, 5.0);
pos2=CGPointMake(5.0, 8.0);
pos3=CGPointMake(8.0, 5.0);
ball1.center=CGPointMake(ball1.center.x+pos1.x, ball1.center.y+pos1.y);
ball2.center=CGPointMake(ball2.center.x+pos2.x, ball2.center.y+pos2.y);
ball3.center=CGPointMake(ball3.center.x+pos3.x, ball3.center.y+pos3.y);
if(ball1.center.x>320||ball1.center.x<0)
pos1.x=-pos1.x;
if(ball1.center.y>480||ball1.center.y<0)
pos1.y=-pos1.y;
if(ball2.center.x>320||ball2.center.x<0)
pos2.x=-pos2.x;
if(ball2.center.y>480||ball2.center.y<0)
pos2.y=-pos2.y;
if(ball3.center.x>320||ball3.center.x<0)
pos3.x=-pos3.x;
if(ball3.center.y>480||ball3.center.y<0)
pos3.y=-pos3.y;
}
...and have added all moving and fixed imageviews in stroyboard.
Thanks in advance
You need to bring that subview to the front of the other subviews:
UIView *viewContainingBalls; // most likely ball1.superview
[viewContainingBalls bringSubviewToFront:ball1];
Use this method to bring the other balls to the front as needed.
Or if you always want the fixed ball to be behind all the other balls you could just send this to the back:
UIView *viewContainingBalls; // most likely fixedball.superview
[viewContainingBalls sendSubviewToBack:fixedball];
There are other methods such as exchangeSubviewAtIndex:withSubviewAtIndex: that also accomplish similar a thing.

How to animate transition between two views without using two view controllers?

I am trying to simulate a deck of cards, where a swipe over the screen makes the next card enter the display from the right, covering the card that is currently visible. I know how to program this using two view controllers and custom segues, but I want to keep it simple. I therefore want to stay within one and the same view controller, copy the current view into a temporary view, draw the new view, and then animate the new view to drift in from the right and cover the old one. Here's my attempt:
- (IBAction)SwipeLeft:(id)sender
{ UIView *sv = self.view;
[self Layout]; // this is where the next card is drawn
UIView *dv = self.view;
dv.center = CGPointMake(sv.center.x + sv.frame.size.width, sv.center.y);
sv.center = CGPointMake(sv.center.x, sv.center.y);
[UIView animateWithDuration:0.3
animations:^
{ dv.center = CGPointMake(sv.center.x, sv.center.y);
sv.center = CGPointMake(sv.center.x - sv.frame.size.width, sv.center.y);
}];
NSLog(#"Swipe left");
}
When I run this code, I do see the new card enter the screen appropriately, however, the 'old' view dissappears immediately and turns into a black screen before the animation starts.
How can I correct this?
Clearly this code does not work, as both pointers point at the same memory location. I decided to solve my problem in a different way. Rather than trying to copy a View object, I create a screen shot, copy the UIImage into a View object, cover the screen under the copy of the old screen when I draw the new screen and than animate that View object. Probably a smarter solution. It works great.

Funny UIScrollView when using presentViewController

Summary:
I have a UIScrollView with zoomable content. If the content is NOT zoomed and I presentViewController, everything is fine when I dismiss that ViewController. But, if I have zoomed the content and then presentViewController, the content and the UIScrollView are all wacky when I dismiss the ViewController. Any help is welcome, this is an awful bug... Thank you!
Test Project:
A simple test can be found here...
http://twostatesaway.com/ModalWithScrollViewTEST.zip
or here
https://drive.google.com/file/d/0B0pG5vRVzBTzdkVzdEtkdmVjdDA/edit?usp=sharing
Screen Shots:
Screen 1: Everything fine. I can show the modal a million times and the content will work as expected after dismissing the modal
Screen 2: Zoom in on content.
Screen 3: When I click the button to presentViewController, the content shifts to the right as the ViewController (in black) is coming up.
Screen 4: Modal is on screen.
Screen 5: When I dismiss the ViewConroller, the content is funny, the bright green view seems to go back to normal, but the button stays in its zoom position, still shifted to the right.
Screen 6: Another funny things is that now I can zoom out more than before. The min zoom is set at 1.0, but now it seems like that is not working.
Try this way...
1) Remove the code from - (IBAction)openModal:(id)sender & make it blank.
2) In story board make the secondViewController class as ModalViewController as below.
3) Drag the line from button to second view & use segue as modal as shown below.
Updated answer
1) clear the viewDidLoad method.
2) Write following code in ViewWillAppear method.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.scrollView.delegate = self;
self.scrollView.minimumZoomScale = 1.0;
self.scrollView.maximumZoomScale = 5.0;
//self.scrollView.contentSize=CGSizeMake(320, 200);
[self.scrollView setZoomScale:self.scrollView.minimumZoomScale];
}
The accepted work around here is to capture the zoom and contentOffset when the modal is coming up, and then set the properties when view is appearing again...
//// Capture values
-(void)viewWillDisappear:(BOOL)animated
{
zoomedScale = self.scrollView.zoomScale;
contentOffsetTemp = self.scrollView.contentOffset;
}
//// This prevents the content from getting messed up (thanks user1673099)
-(void)viewDidDisappear:(BOOL)animated
{
[self.scrollView setZoomScale:self.scrollView.minimumZoomScale];
}
//// Then reassign them values
-(void)viewWillAppear:(BOOL)animated
{
self.scrollView.zoomScale = zoomedScale;
self.scrollView.contentOffset = contentOffsetTemp;
}

Once swiping on UIImageView with animation the animation stops

I have a UIImageView with animationImages and it works fine
self.imageView.animationImages = [self loadImages];
self.imageView.animationDuration = 15;
[self.imageView startAnimating];
I've added a swipe gesture that, in the selector of the swipe I want to do the following:
find the image that is currently shown
move to the next/previous image
continue the animation
Post your gesture recognizer action method.
It will take some tinkering, but it should be possible to do what you want to do.
I suspect that you will have to stop the animation, juggle the order of the images in the animation array, and then start the animation again. The image view should revert to the normal content image when the animation stops, so you might want to set the normal image to the image on which you stop if you get flickering when you stop the animation and restart it.

Dragging uiimageview into a "trashcan" while zoomed in on a uiscrollview

Hey everyone. I've searched the web and really haven't found a problem quite like this. My set up is as follows: I am trying to make an app where a user drags uiimageviewss on a uiview inside a uiscrollview (which can zoom in), but also drag the image to a trashcan to be deleted. When the scrollview is zoomed in, the user can still drag because I have subclassed uiimageview and overridden the touchesMoved method. I want the user to be able to drag the uiimageviews to a trashcan in the bottom right corner of the screen. What I implemented already works when the uiscrollview is normal zoom scale, but when you zoom in you cannot drag the image to the trashcan, because well, the trashcan is a subview of the controller's view itself (this was so that it wouldn't zoom with the uiview) and of course is not in the right coordinates of the screen for the uiscrollview.
I've found a view method called ConvertRect that converts a rectangle to the coordinates of whatever view you give to the method, but this doesn't seem to be working. I do a check within each mapimage(the imageview subclass) that checks the frame of the uiimageview intersects the frame of the trashcan. So I try this method before I do that check, but like I said it doesn't seem to be working.
So with all that complicatedness, let me say in a nutshell my problem. I want to drag images over to a trashcan regardless of what zoom level at uiscrollview is at. I can make the trashcan part of the uiscrollview but I need a way to make it keep in the bottom right corner and also not zoom when the uiscrollview does. Any ideas would be so greatly appreciated, thanks guys. :)
I had the exact same challenge.
In can just describe it in short:
When you start dragging the image REMOVE it from the UISCrollView and add it as a subview the the main view of your ViewController.
make sure that the image won't get lost in the process (means: someone still retaining it).
While dragging, constantly check to see if your image entered or left the boundaries of the trash can. you can do it with the method bellow:
-(void) checkForTrashCan
{
CGRect rect = [self.delegate.trashCan convertRect:self.view.frame fromView:self.view.superview];
if ([self.delegate.trashCan rectIntersectBounds:rect])
{
if (NOT self.isInTrashMode)
{
[self enterTrashMode];
}
}
else
{
if (self.isInTrashMode)
{
[self exitTrashMode];
}
}
}
When the method rectIntersectBounds is just a simple extension method for UIView class that i wrote:
-(BOOL) rectIntersectBounds : (CGRect) rect
{
return CGRectIntersectsRect(self.bounds, rect);
}
When the drag ended check if your view is inside the trash can, and act according to the result.

Resources