UIScrollView with "Layers" - objective-c

Sorry about the title, but I don't know how to say what I want.
I want a UIScrollView with layers, like a image and a text above it, and when it is scrolled, the text is moved faster than the image. Like this video, exactly at 0:13; I've thought about a UIScrollView inside a UIScrollView, but would not be something really good.
Thanks for the attention,
Alberto

You could place an instance of UIImageView behind your UIScrollView. When the method scrollViewDidScroll is called, you can easily change the position of your background view dependent on the offset of the scrollView.

Related

Objective C draw in view dynamically

I have seen many examples of views being subclassed to override drawRect, but that approach is pretty static (at least as far as I understand).
What I'd like to do is set up a very simple drawing canvas. In that, I've got a view with a UIPanGestureRecognizer attached to it. Whenever the gesture fires a new position, I'd like to draw a circle of a fixed size and color in that position of the view. The gesture recognizer is attached to the view, but it fires a selector in the view controller. I already have a subclass of a UIView. So, what would be the best approach?
Thanks.
What you need to do in this case is still to override drawRect!
The difference is that you, when recognising gestures, need to keep track of the location(s) in which this circle should be drawn, and access that information the next time you are redrawing the view, essentially building up an image in memory that you draw into the view.

UIImageView overlapping effect inside a UIView

Check this URL http://krystalrae.com/
Scrolling down you will see a girl's cloths are changing on mouse wheel scrolling.
I have to create a iPad application where 3 images will appear likewise. The difference will be that in my case image change will occur horizontally rather than vertically in website. Also, i have to make it inside UIView with events touchesBegan, touchesMoved, touchesEnded and touchesCancelled
Help will be appreciated.
Thanks.
From your comment I gather that the problem is the resizing of the images in UIImageView when changing the bounds of the view.
You can set the contentMode of the image view to something else. The default is UIViewContentModeScaleToFill which is not what you want.
You could, for example, set the lower image view to UIViewContentModeBottom, and the upper image view to UIViewContentModeTop.
Don't forget to make sure your image views have sett the property maskToBounds set as YES.

Irregular shaped buttons using OBShapedButton with hidden image

I am trying to make an irregular shaped button with the OBShapedButton class. That's ok, created it without any problem, however I need the image to be transparent. So, I just want an area from the image which will be clickable, but the image won't be seen.
I tried setting alphas on image, imageView and on the button itself, however it doesn't work neither way.
How should I do it?
Maybe it could be done by something else, not an UIButton, but unfortunately I didn't find anything on the net that I could understand and use.
Ok, so the easiest way on how to do this is:
Subclass UIButton and add touchesBegan, touchesEnded, touchesMoved,
touchesCancelled.
Then on touchesBegan, hide the image of the button and show the correct image in background.
And finally on touchesEnded or touchesMoved, show again the image of the button.
Hope it will help someone :)

Resizing an NSView smaller than its subviews?

Couldn't find anything on the net about this and wondered if anyone on SO has a solution.
I have an NSView with several subviews that are centered by removing the left and right anchor points. When I resize my view, programatically or with the mouse, to a smaller width than the subviews: it pushes them off center. Has anyone come across this before and do you have a solution?
EDIT: I want to be able to resize my view to a zero width. The reason being, the view is actually part of a split view and I have hooked up a button to 'collapse' it. When it collapses all of the subviews are pushed off-center and aren't re-centered when the view is resized, effectively un-collapsing it.
I have solved my problem now and thought I would share incase anyone comes across this issue in the future.
No amount of playing with autosizing options or view layouts in Interface Builder seemed to stop my subviews from getting moved off center. I did manage to find this link here and from this page, the advice:
Springs and struts, as currently
implemented, are really no good for
anything but keeping either one or
both sides of a view "stuck" to the
nearest edge. Any sort of centering
behavior, division of gained/lost area
between multiple views, etc. has to be
done by hand.
Based on this I overrode my view's setFrame: method and manually laid out my subviews using their setFrame: method. This works great and gives me the results I'm looking for.
There is the same issue using NSSplitView, resizing here one Subview to be smaller than the Subview Subviews makes sense,e.g. having small charts in the upper subview, and an rss reader in the lower subview.
If you want to show only the rss reader in the lower subview, you can "hide" the upper subview, but after resizing the upper subview the NSImageView are not layed out the same as in the beginning. Check this nib/xCode Project and the following screenshot to see this behaviour.
Only workaroung is to override the resize function to stop getting smaller.

NSScrollView frame and flipped documentView

I have problems with NSScrollView, It is not displayed the way I want.
Yes I know there is a lot of post about it around the web, I need to override the isFlipped, in order to make it return YES, in my NSView subclass.
Ok, it's done, so now, my scrollView scroll from top to bottom, and not in the reverse way, as it was before overriding isFlipped.
But, this is the second part, my real problem, which I didn't found any answer on the web, how the hell I'm supposed to code, or create my view in interface builder, if everything is flipped? If I put something at the top, it is displayed a the bottom… do you have any magic trick to handle that?
And my last problem, is the NSScrollView frame. before setting the documentView of my scroll view, everything is fine, the scrollView is displayed at the place I choose, but, when I set the document view, it looks like the scrollview frame looks bigger, so I have to resize it…. is this a normal behavior?
Thank you very much.
The answer is usually to create an NSClipView subclass that returns YES from an override of isFlipped:
Then in IB, set the scroll view's content view (clip view) to your subclass.
Being flipped only applies its coordinate system to that exact view, not everything down the whole view hierarchy. So whatever you're putting directly into your flipped content view needs to be aware that it's flipped, but nothing else does.
And if you don't want it to work that way, just don't ask for it to be flipped! There's no rule that says that the document view of an NSScrollView has to be flipped, it's just very common for anything with variable-height content to be laid out top to bottom, which is easiest to do in a flipped view. If the layout you're doing works best as bottom-anchored, by all means, keep it unflipped, whatever's easiest. (And anything in Interface Builder should be fine anyway…did you actually see this problem, or are you just speculating that it might happen? I've never seen this issue…)
Setting the document view shouldn't change the size of the NSScrollView. You may have something else going on besides just that…