Using AFOpenFlow: adding subviews not just images - iphone

I am using the AFOpenFlow library to generate a coverflow-like effect, but trying to add arbitrary UIViews to an AFOpenflowView, not just images. I am doing this by creating a subclass of of AFItemView, lets call it NewAFItemView, which represents the view I want to add. I also extended AFOpenFlowView, call it NewAFOpenFlowView and overrode the method
-(AFItemView *)coverForIndex:(int)coverIndex;
In the overridden method, I allocate an NewAFItemView object and return it as the cover view for that index. The NewAFItemView views appear correctly in the open flow but scrolling is immediately disabled. Switching back to allocating AFItemViews works but using NewAFItemViews does not scroll.
I have not overridden any of the touch events.
Any ideas on what might be happening?
Cheers.

why donĀ“t you use iCarousel?
https://github.com/nicklockwood/iCarousel
i use this, and it works perfect for uiviews =).

Related

iOS Creating a list of tags

I'm currently trying to implement a feature in my app that shows tags for a post. I want it to work very similar to that of tags here on StackOverflow, in that they have a colored background.
Another example, are the Inline Labels here.
I'm just not quite sure on how to get it implemented. My first guess would to create an array of UILabels... Any suggestions?
Figure out what you want the tags to look like. If you can achieve that appearance with existing components like labels or tokens, then great, problem solved. If not, creating your own UIView subclass that draws a background and bit of text is pretty simple -- you wouldn't need to write much more code than a custom -drawRect: method, and even that should be easy. For example, if you wanted something that looks like the Twitter-ish inline labels, you could start with a resizable image and then draw your text on top.
Don't be afraid to create your own view classes... it's fun!
You probably need to write two classes.
The first (let's call it HorizontalLayoutView) will extend UIView. It will serve as the container view to hold all of the tags. It would override the layoutSubviews method to arrange the subviews by setting their frames. Create one instance of this and add it as a subview to your existing view.
The other (let's call that TagView) will also extend UIView, or perhaps UILabel. Instances of this class will represent each tag. Create one instance for each tag and add it as a subview to your horizontalLayoutView instance. In the initWithFrame: method, you would customize the tag to look the way you want. You can also override the drawRect: method to further customize its look.
If you are adding the tags dynamically after the view is already displayed, you may need to call setNeedsLayout on the horizontalLayoutView instance to get it to adjust properly.
Hope this will get you started in the right direction.

Obj-C, app moving around UIImageView's but need to return to the view and reset positions?

I've probably setup the UIImageViews incorrectly. I added them in interface builder. I then allow them to be moved around the view with touchbegan etc.
I'm using a navigation controller and I need to have the positions of the UIImageViews reset to how they were positioned when the view was loaded.
I thought I could re-initialize them in viewWillAppear, but I don't seem to be able to do this.
Can someone advise me what I should do to make this functionality work?
You'll have to store the positions somewhere. You could even subclass the UIImageViews and put in a custom property like CGPoint initialPosition.
You could as well load the nib file again and try to map the UIImageViews you find in it to the ones you are currently showing, but personally I'd stick to some local storage.

iPhone SDK moving a view and its subviews to back

I have an application with multiple views that contain subviews. I know that you can hide or make visible a view and its subviews by setting the hidden property to YES or NO. However with a number of views, to use the hidden property requires keeping track of what view is being displayed. I thought I could use sendSuBViewToBack: to hide a view and moveSubViewToFront to make it visible. However, these methods appear to only act on the specific subview and not its child subviews. For example, a view with a couple of labels on it, when sent to the back, the labels remain visible.
Is there any way to make this behavior work besides using the hidden property?
Thanks,
Jim
UIViewController seems like what you're looking for. Or rather, what you should be looking for.
I'm not quite sure what exactly you're having trouble with here. As long as you're keeping track of each "container" view (perhaps using a #property), you should be able to show/hide them on demand using a method in your code (which can be as simple as hiding all container views, and then showing the one you desire).

When is 'drawRect' called?

I have some custom drawing code in drawRect which also performs some calculation of sizes.
When is the earliest I can be sure that this code has been loaded, e.g. if I want to modify it's containers size accordingly?
-[NSView viewWillDraw] is a reasonable place for last minute layout.
I have some custom drawing code in drawRect which also performs some calculation of sizes.
When is the earliest I can be sure that this code has been loaded, e.g. if I want to modify it's containers size accordingly?
An object can't exist until its class is fully loaded. If you have an instance, the class that it's an instance of is completely loaded, because you wouldn't have an instance of it if it wasn't.
As for when it's called: It's called when you need to draw. This normally happens as part of the event loop, if anything has marked the view as needing display. It is possible to directly tell an NSView to display, but, as far as I can tell, this is not possible for UIViews.
So, if you need to do something to it before it gets told to, either do it immediately after creating it or, if you're about to set the view as needing display, do it before you do that.
Just before the view is displayed or when you call
[aView setNeedsDisplay];
I just created my first customView app. This was one of my questions. my drawRect method was called once upon creating my window (or recreating). And millions of time when resizing my window.

iPhone: rendering of different views possible?

I have a problem, I can't solve properly.
In short: I want to create a single view (say: UIImageView) out of multiple subviews - i.e. it consists out of multiple ImageViews and TextViews. The thing is, I want to sort of 'render' them to be a single View.
Say, I take an image, add some description below, add a title above, and maybe another little image at the bottom. I want this whole thing to be a single UIImage to make it sort of 'listen' to one (e.g.) swiping gesture, which I cant tell to bring the new image to display.
Does anyone know the best way to achieve this? So far my results were fairly poor.
Any hints are welcome!
This is definitely possible. You seem to know about views and subviews, but should also read up on the "UIResponder" class and the "responder chain". The master view that you want to contain them all won't be a UIImageView, though, because that exists to just show an image. You can make all the ones you talk about subviews (addSubview: or in Interface Builder) of a plain UIView that you subclass yourself (say, MyContainerView), which then itself handles the gestures. If you want to take advantage of free scrolling on swipe, you could instead put your container view into a UIScrollView, which has its own set of semantics that you can leverage. For this latter, you should check out Apple's sample code for scroll views (don't have a link handy but should be easy to find) which embeds multiple image views in a scroll view.