I have an UIImageView which covers all of my screen. The pictures that I'm displaying are bigger than it and the .contentmode is set to the.scaleAspectFill So the UImageView is just showing a cropped version of each picture.
In front of them is a CollectionViewController which consists
of multiple pages.
I've used scrollViewWillEndDragging to change my background picture when I move through the pages with a short animation ( each page has a specific background).
Please Help on:
How can I make the background picture move with my touch move horizontally until the scrollViewWillEndDragging happens and move back to its original position if the scrollViewWillEndDragging didn't happen.
Thank you for your time.
Related
I want to create a page with a big image as background and buttons that users can interact with.
So imagine I put a big image such as a piece of map into the screen, but I only show a corner of the map in the display. So if a user wants to see other parts of the map, they have to "scroll" and navigate to wherever they want.
Meanwhile I also want to put a button they can tap on, and that button should lead to a php webpage (in-app, not opening in safari or else) or information page about sites and buildings in this location.
I am a rookie and I haven't have any code written down yet. I am thinking about using UIScrollView and UIButton, but am I on the right direction? Any advice?
Thanks in advance!
First you need a way to pinch zoom the image. In this mode, you can drag the image in any direction that you want. A common method can be found here. A scroll view can only scroll horizontally or vertically but with that image zooming, each image can be zoomed in and then dragged to any direction you want. You can have a scroll view with only one image.
After you have the image zooming ready, all you need to do is to create a subview on your screen to cover part of the image view or scroll view, whatever you used.
I have a UITableView with rows.
Each row has a small UIImageView aligned to the right (a "bookmark" icon)
The UIimageView has a UITapGestureRecognizer associated.
cell.favoritedImageView.userInteractionEnabled = true
cell.favoritedImageView.addGestureRecognizer(gestureRecognizer)
The problem is that to actually tap it with the finger (in a real device), you have to use the tip of the finger and be very accurate, because the image is small.
If you miss tapping the imageView, the cell is tapped (didSelectRowAtIndexPath) and you end up executing a show-segue to another view, so you have to go back and try again (not cool)
Question: what is the best way to solve this? I want it to be easy to be tapped.
I have some ideas:
Create a larger image with transparent surrounding (ie: crop out with transparent background) -- downside is that I also use this image in other views, in which is not tappable, so I'd have to create two versions of the image
Put the image inside a UIView and make the UIView big and tappable instead of the UIImageView
Add padding to the UIImageView (will this work? or the padding is not recognized in the UITapGestureRecognizer?)
Per your own suggestion, you should create a transparent view that is much larger and attach the UITapGestureRecognizer to the view and then nest your smaller image within the view. That way appearances are the same, but you handle a much larger area for the tap to be recognized with selecting the cell.
I want to create a view in which I like to have animation such as the one present in iOS 8 Weather app.
I try to explain more what I have done. If anything is incorrect please guide me.
In the top I put a label for the temperature. (The big one)
Below that label, I put another label to show some text. In the Weather app, there is the horizontal scrollview showing the hourly forecast.
Next is the Table view.
What I want to achieve is that when I start scrolling, the first label disappear smoothly and the second one go to top of the screen and the TableView stretches to show more content.
When I scroll back to the top, I want the whole process to revert.
What is the best way to do this?
I've recently re-created the iOS8 Weather app's scrolling effect for an app I'm creating.
The complete code is too long to post here but for anyone who's interested, I've put it on GitHub. You can download and run the project to see how it looks. Improvements to the code are welcome:
UIScrollView with masked content.
It works like this:
You have one scrollview (the size of the screen), which contains a subview (the mask) which in turn has a subview (the content). We also add a large label to the top of the screen (in the Weather app, this displays the temperature).
Then you use the scrollViewDidScroll delegate method to keep the mask fixed to the screen as the user scrolls. You also use this method to stretch the mask upwards at first.
Fixing the mask to the screen means that the mask's subviews (our content) also becomes fixed. But we want it to scroll, so we do the opposite to the content of what we did to the mask (again, using scrollViewDidScroll).
We need the mask to actually behave as a mask, so we set clipsToBounds = YES on the mask.
Finally, we use the scrollview's offset during scroll to move and fade the big label at the top of the screen.
To make it behave exactly like the iOS8 Weather app, we need to also do the following:
Cancel any scroll touches that happen above the mask, i.e. over the large temperature display.
Ensure that the initial scroll that moves the temperature display is completed programatically if the user doesn't complete it.
Add a sideways-scrolling subview which is anchored to the top of the mask.
I haven't done these yet, though.
In the Facebook app, when you're on the feed, and you tap on a photo to view it, a few things happen:
The image animates/moves to the center of the screen, no matter where its current position in the table view (middle, partially off the screen towards the bottom, top, whatever)
As the image moves to the center of the screen, the rest of the table view is faded out (alpha = 0)
When you drag the image up or down, the alpha of the table view is restored proportionally (I think) to the offset of the image from the center of the screen
At this point you'll notice that in the Feed, the place where the image used to be, is now empty (giving you the impression that you 'brought' that image up front). You see this by dragging the image up/down and you can see the Feed/table view behind the image.
Following #2, if the image is already proportional (that is, the image's preview on the Feed/table view was a proportionally-scaled one without any cropping) then it just moves to the center. If the image was cropped at all (because it was too tall, etc to fit properly in the Feed) then the rest of the image is revealed at the same time that it is moved to the center of the screen.
Once the image moves to the center of the screen, the gallery view controller elements show up (Done button, Like/Comment buttons, etc)
Following #4, if you swipe to another image (swipe left/right in the full-screen image view to another image in the same album), and then attempt the drag up/down in #3, you'll see that the first image is back to where it was in the Feed.
Finally, if you drag the image up/down past a certain threshold, it is dismissed and the Feed is revealed again.
This is what I think is happening conceptually, and I'd like some confirmation if this is the right approach (these bullets below don't map to the bullets above):
When user taps on an image, add that imageView as a subview of the table view's container view, but add it at the exact same position so that the movement of the imageView from the cell into the main view is not seen.
Then animate the movement of that image to the center of the screen. At the same time, reduce the alpha of the table view so that it reaches 0 at the same time that the imageView reaches the center of the screen.
Once the image reaches the center of the screen, push a modal view controller without animating it, and add the imageView as a subview of the modal view controller's view (effect #6 above)
Any dragging of the image reduces the alpha of the modal view controller and increases the alpha of the Feed table view (effect #3 above) and dragging above a certain threshold triggers the animation that hides the gallery and shows the Feed again (effect #8 above)
Questions:
Am I on the right track? If so, how do I bring the imageView from the cell into the front view - and keep it at that very same position?
When you swipe to another image, the original image is 'restored' into its original location in the cell of the table view. Is this actually just moving one imageView from one view to the next? How the heck do you send it back to the original cell - keep a pointer to that cell when the user taps on the image, and then do something like customCell.imageViewContainerView addSubview:originalImageView? This then needs to be reversed if the user swipes back to the original image?
This whole thing to me seems like a non-trivial implementation, but I think the effect is awesome and I'm also damn curious as to how it's done. Am I overthinking it and there's actually a really easy way to do it, or am I right to give props to whoever wrote the FB app?
Am I on the right track? If so, how do I bring the imageView from the cell into the front view - and keep it at that very same position?
I think that you are right on the conceptual steps. It's not difficult to get the imageView from the cell and add it to the controllers view. You can use the methods like
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view
to get the correct position for the imageview.
When you swipe to another image, the original image is 'restored' into its original location in the cell of the table view. Is this actually just moving one imageView from one view to the next? How the heck do you send it back to the original cell - keep a pointer to that cell when the user taps on the image, and then do something like customCell.imageViewContainerView addSubview:originalImageView? This then needs to be reversed if the user swipes back to the original image?
I think that this is made by some kind of protocol between the gallery and the table view controllers. Maybe it just hide/show the image, and the images in the gallery are actually a different object.
Anyway, if you want to use the same imageview, you can send the object with the protocol between the two controllers.
Hope this helps a little ;) I think that key is in the convertRect methods.
I have a UIView in which I get certain information about a user, wthin a bunch of textfields and a bunch of photos of him, if available.
No Im a bit limited here, so I must have a UIImage or UIImageView on my View (only the first half of my view, to display this images.
Up to now I have a array of this images in the background and as soon as the user swipe over the UIImageView, the image shows the next.
But it's ugly, becuase there is no real paging (you know, see the second image in pieces while you swipe, at the moment its only a UIMageView.Image = xxx and its ugly) and no zooming (zoom on click).
Any idea to solve this?
Use an UIScrollView and place all of the images in it (as UIImageViews).