I want to make an application like photos of iPad in which it displays photos in grid manner and after clicking over custom-view it animated from its current position.
I just want to know how to animate view from its current position like if i click over the custom-view which is first line then it will show that custom-view animating from top position and if i click over the custom-view which is in bottom line then it will show and animate custom-view from bottom position and same for middle line also. Any help and suggestion will be appreciated.
If you don't specify the from value then the current value is the default. If you still want to specify the default value then the current frame of the image would probably do.
Depending on what happens next in your application and if the images resize or not you may need to animate a transform as well. Otherwise just animating the frame from its current value to [[UIScreen mainScreen] applicationFrame]; will be a good starting point.
Also, depending on where your image is in the view hierarchy you may need to move it to appear on top of tab bars and navigation bars if you truly want the image to appear full-screen when tapped.
Related
I'd like to have an interactive animation where a view transitions from one set of constraints to another as the user drags up/down the screen. The background image should shrink vertically (easy), and the profile image should change from being horizontally and vertically aligned to the background image to being anchored to the top and left corners of the background image. Is this possible?
Yes, it is possible, and you can see this effect in the Avvo app, for example (in the lawyer profile screen). The trick here is to smoothly transition from one set of constraints to another.
Here's an outline of how to do this:
add a UIScrollView. Add the view you want to animate as a subview to the scroll view.
Make your view controller implement
UIScrollViewDelegate
In the delegate method
scrollViewDidScroll(_:), update the constraints' constants as
needed.
Also in that method, when contentOffset crosses a
threshold value, flip to a different set of constraints, by setting
their active property to true or false.
To keep the view (the headshot image, in my example), pinned to the top as you scroll, just continuously update its top spacing constraints based on the contentOffset.y value.
Achieving a perfectly smooth transition may take some trial and error, but it definitely can be done!
Here are the screenshots showing the transition as you scroll up:
My application has a UIWebView which consists of an UIImageView as its subview, when i change the orientation of the device, the image in UIWebView is not affected and it remains in the same position as before. So is there a way to fix this issue. i want the image to automatically allign to its respective orientation.
How about use "Size Inspector". Set as below, the image view will move to new position.
Can you see what I have done in this picture? I removed all red lines around square so that the view moves to keep ratio of distance to edge of screen.
Have a look on the autoresizingMask which defines how the view behaves if the superviews bounds changes. In Xcode you can do it in the Interface Builder/Size Inspector.
I would like to show a gallery using a horizontal ScrollView; i would like to show an item and, when the user swipes, animate to a certain position to avoid to see partial images but centering the next item to the screen and "dock" the item to (x,y) coordinates.
How can i do it?
I hope I understand this right. When the user swipes, you want to scroll to the next picture (using an animation). Also, the scrollview should then snap on the picture so that it doesn't display any other partial images.
If this is the case, then you can use scrollView.pagingEnabled = TRUE. You will have this snapping (docking) and swiping features implemented.
All you need to do is to arrange the pictures inside the scrollview so that it is only one picture per screen.
If you expect a lot of images, then you can improve this design by storing only the previous, current and next pictures. When the user scrolls from current -> next, then you will have something like this:
previousImage = currentImage;
currentImage = nextImage;
nextImage = //Load the next gallery image
If you need more help, feel free to ask.
I'm about to create an app with the same technology like the Google+ app. I want to reproduce the "stream"-viewcontroller.
Currently i've set up a scrollview with paging and pagecontrol, but I can't get how the bar under the navigationbar in the Google+-app is created. It shows the titles of the current page and the pages to the left and right. It also has a zoom-effect that zoom in at the current visible pagetitle.
Anyone has any ideas?
One way to do it would be to create your VC, throw a scrollview in it whose x, y and width are the same as your backing view, but whose height is the height of your backing view minus however high you want your titlebar to be. Create a separate view for that. Your paging scrollview will work fine for the content area.
For your titlebar, you'll probably just set up some CABasicAnimations and keep some images off screen, sliding them around as you see fit, or what-have-you. This is one approach you can use.
I have a UISCrollview. Inside this scroller I have a picture and over the picture I have some objects (as subviews of the picture), like layers in a Photoshop composition. So, if I zoom the picture, the objects will zoom. If I scroll the picture, the objects scroll.
Now consider this: I have the picture zoomed in. The picture is now larger than the iPad screen. I am seeing the top half of the picture. I touch an object that is over the picture and start dragging it to the bottom of the screen. My intent is to drop the dragged object at the bottom of the picture, but as the picture is zoomed in, I have to drag the element to bottom of the screen, release it, scroll the picture up and then continue dragging the object.
What I want is this: I start dragging and when I arrive at the boundary of the screen, the scroller starts scrolling automatically showing parts of the image that were down or up.
What do I need is to know the rect that is visible, a kind of inverse of scrollRectToVisible...
Considering that the picture can be zoomed at any level, how do I know if the element I am dragging is near the border. BTW, how do I know what part of the scroller is being shown, even if it is zoomed?
thanks.
The visible rectangle has a size of scrollView.bounds.size and an origin of scrollView.contentOffset, in the coordinate space of the scrollview. Depending on what exactly you are doing, you may need to use convertRect:fromView: or convertRect:toView: to convert it into the coordinate space of the zoomed view.