Refresh UIView with paging animation - iphone

I have a UIView that has controls built based off a date. I want to flick to change the date and refresh the UIView with an animation like the paging animation. Is that possible? I do not want to create multiple copies of my UIView because it is already close to exceeding memory. 2 copies of my UIView would definitely crash the phone. Does anybody have any suggestions? Please let me know.

Although I haven't tested it, you should be able to use the same instance of the UIView that would generate a 'flip' or whatever animation using the same UIView as the underlying view and the overlying view.
I've stumbled into this accidentally, trying to get some animations working.

Related

UIImageView in UIScrollView

I have a series of UIImageViews in a UIScrollView. The user can zoom into each one, but after a bit of usage the images start disappearing, and then various images in the app disappear. I'm wondering if anybody has any any experience with this and has any idea why this could be happening?
Its a complete guess until you give us source, but chances are that you are doing something like not retaining your image views or are adding them to another view – effectively removing them from the first view they were in.

Rearrange subviews in UIScrollView like App-Icons on Home-Screen

Hej folks,
I got a question to you: I got a UIScrollView in my application containing numerous subviews (all direct subclasses of UIView). Now I want to give the user the possibility to rearrange these subviews inside the scrollview. Is there anyway to make it look like the way we all can change the icons on our homescreen (auto-rearrange)? I would really appreciate any help!
Thanks in advance,
Tim
Unless you use some custom tool kit (I'm not sure there exists a custom tool kit or API to achieve this), I think you should create them from scratch.
I'm also creating very similar thing you said. In an UIScrollView instance, I added small subviews and can order them only vertically by dragging. Also, I can take any subview to the outside of an UIScrollView instance. (a little bit tricky)
There are two ways to build them. (small subviews == icons)
1a) Implement touch events(gestureRecognizer or touchesBegan, Moved, Ended, Canceled) in a main subview of UIScrollView that contains many small subviews.
1b) Implement touch events in each small subview.
I chose 1b because I want to use small subviews not only in UIScrollView but also anywhere in my program. But with 1b, it was a little bit hard to prevent multitouch among these small views. Also I felt that with 1b, touch events in small subviews are more free from the complicated responder chains of an application.
2) Create a NSMutableArray instance that contains a list of small subviews.
3) Implement a function that displays a NSMutableArray instance onto a main view of an UIScrollView instance by enumerating it.
4) Implement a function that enumerates a NSMutableArray instance and checks whether a current touch position of small subview is in a frame of any small subview of a NSMutableArray. (or checks whether a current moving small subview's frame interesects a frame of any small subview) You can use CGRectContainsPoint or CGRectContainsRect functions from CGGeomtery.
5a) If yes, then you can just change frame of every small subview of a NSMutableArray.
5b) If the user releases a finger outside of frame of any small subview, then do nothing.
Simply using block-based animation methods(iOS4 and later) or begin/commit animation methods, you can create them like a home screen.
Very Good Example For Scrollview with Pagecontrol like iphone home Screen
https://github.com/jarada/myLauncher

i*-sdk: Placing a bubble on top of all controls

I've got a problem thats been perplexing me for a while. I have a custom control for the iPhone sdk. When the user touches the control I want to draw a small bubble above the users touch position with some information in it. A bit like a thought bubble in a cartoon.
Initially I've done it by adding a UIView subview to the control. However if I use the control where I don't have control of the z-order, for example in a table view, then the bubble will be drawn under other controls.
I've looked around but I'm not sure how to approach this problem. Everything I've read seems to indicate that you need to know the tree structure of the controls. Ideally I'd like to apply it to some layer that sits over the window as a whole, but I'm not sure how. I've also look at core graphics but cannot see any obvious answers.
Does anyone have any ideas of perhaps something they can point me at which will help.
Thanks
If you want to add a UIView to the 'top window', you can use the application UIWindow for that.
UIWindow is a subclass of UIView, so you can just use - (void)addSubview:(UIView *)view to add the new view to the window.
[[UIApplication sharedApplication] keyWindow] addSubview:yourView];
You could try adding it as a subview of the window, though, I don't think that's the most appropriate solution.
Personally, I would add my control as a subview to whichever view (maybe a table cell) and then tell that view to bring your control to the front.
[tablecell bringSubviewToFront:myControl];
That way, when you display your bubble, it'll be on top.

Making view transitions fast - do you use this hack?

I have an iPhone app that displays a modal view controller. The modal view controller shows two instances of a custom subclass of UITextView called RoundedTextView, an MKMapView, and a UIToolbar. I construct the viewController only once, and reset its data and present it each time the user summons it.
When showing this view controller with presentModalViewController, I noticed that the animation to show the view was choppy on the 3G. So, to speed it up, I set the alpha of the MKMapView and the two RoundedTextView objects to 0 on viewWillDisappear and back to 1 on viewDidAppear. This made it nice and fast. I also presume that I could remove the views from the superview to speed it up as well.
Does anyone else jump through these kind of hoops on the iPhone. Is there something else I should be doing to avoid this hack?
It's not a hack to simplify drawing during animation in order to make the animation more smooth. It is indeed a very valid technique.
You may be able to achieve similar performance improvements by setting all UI elements to Opaque, a technique also used to fix table view cell performance issues. You just have to make sure background colors match.
The main problem I had was I subclassed UIButton to make gradient buttons and I had the boundary mask enabled. This made the performance terrible. I removed that option and made my buttons square and it's blazin now.

Drag & sweep with Cocoa on iPhone

I'm about to start a new iPhone app that requires a certain functionality but I'm not sure if it's doable. I'm willing to research but first I just wanted to know if I should at least consider it or not.
I haven't seen this in an app before (which is my main concern, even though I haven't seen too many apps since I don't own an iPhone), but an example would be the iPhone shortcuts panels: you can hold on an app, and then drag it to another panel, sweeping while still dragging it. But this is the core app, is it possible to reproduce something similar within a normal app?
I only need to be sure it can be done before I start digging, I don't need code examples or anything, but if you have some exact resources that you consider helpful, that would be appreciated.
Thanks!
Yes. If you have your custom UIView subclass instance inside a UIScrollView, your view controller just needs to set the UIScrollView to delay content touches and not allow it to cancel touch events.
[scrollView setCanCancelContentTouches:NO];
[scrollView setDelaysContentTouches:YES];
When the user taps and holds in the custom view, the event goes to that custom view, which can process the touch events to drag an item around, but if the user quickly swipes, it scrolls the view.
The "panel" view that you're referring to appears to be a UIPageControl view — although, perhaps, the specific incarnation of this view that Apple uses for the iPhone's home page may be customized.
Instances of generic UIView views that you might touch-and-drag will receive touch events. By overriding methods in the view, these events can be processed and passed to the page control, in order to tell it to "sweep" between pages.
If I wanted to do what you're asking about, that's how I might approach it. It seems doable to me, in any case.
Start with this: Swip from one view to the next view
Try using a UIButton that tracks the time since the state of the button changed to "highlighted". You may need to do this in order to track the dragging and move the button around:
Observing pinch multi-touch gestures in a UITableView
Check to see if the button starts overlapping one side of the screen while being dragged. If s certain amount of time elapses since the button first started overlapping the edge and then manipulate the UIScrollView so that it switches to the next page on the corresponding side of the screen
You may need to use NSTimer to keep track of how long the button is held down, etc.
In any case there's no reason why this couldn't work.
If UIButton doesn't work then perhaps try a custom subclass of UIControl (which tracks the same touch down actions etc.). If that doesn't work then use the window event intercept thing to track everything.