Tap navigation bar to scroll to top - iphone

I have a really long UIWebView, and I need to add a way for the user to tap the UINavigationBar to scroll to top (something like the Facebook app, where it's little glow when you tap).
How can I do this?

In iOS5, you can now access the UIScrollView directly, allowing you to scroll to top.
[webView.scrollView scrollRectToVisible:animated:]
That should take care of everything that you need.

You could use javascript to scroll the web view to the top. You could execute the javascript from the Objective-C side using
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

Related

How does Facebook iPhone app implement the pop-over window for notifications?

How does Facebook iPhone app (4.1) implement the pop-over window for notifications (see below for screenshot)? I thought this was only capable on the iPad. Is this a lookalike that they have custom built?
Check out this library which can implement pop over menus like facebook app: https://github.com/50pixels/FPPopover
I think it is far more complicated (and cleaner) than either of answers (guesses) so far. It is likely a completely separate view controller with it's own content view that is being added as a subview of the container view.
There are some libraries that so a similar thing, here is one for example:
https://github.com/KJoyner/SeaGlass/wiki/SGPopoverController-Documentation
http://www.facebook.com/note.php?note_id=107632999326583
https://github.com/chrismiles/CMPopTipView
My first guess would be that the "popover" is just a subview within the mainview.
First you create the subview, then hide it mySubView.hidden = TRUE; . When the user taps on the Globe button just "unhide" mySubView.hidden = FALSE; the subview with a nice 1 second animation (which will make it fade in).
I imagine that the edges with the rounded corners, subtle inner glow, and outer shadow are part of a resizable 9 part image. From there, it just about placing it on screen stretching it out and drawing the arrow at the appropriate location to line up with the bar button item.

Swipe to change views

Is the following easy to code?
I have a tableview and when the user selects a cell a detail view is loaded.
I want to allow the user to navigate throughout the items/detail-view representing the items in the tableview by left and right swipes, working in the same way as e.g. the home-screen of the iphone (e.g. while swiping, one page is moving off the screen and the next appears).
I have seen this implemented in the MobileRSS-APP, so it is possible, but I just have a hard-time figuring out the way to do it properly.
Thanks a million in advance! I am still trying to find my feet with cocoa-touch...
This is not a secret, Apple provides the sample code called the PageControl that demonstrates exactly what you want to achieve:
This application primarily demonstrates use of UIScrollView's paging functionality to use horizontal scrolling as a mechanism for navigating between different pages of content.
I implemented it in many of my apps.
The iphone home screen (springboard) works with a scroll view set to paging enabled.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setPagingEnabled:YES];
Then, lets say there's two pages of apps to swipe through - you set the content size of the scroll view to twice the width of your view:
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width*2, self.view.frame.size.height)];
And thats how that is done. :) I don't know if its the same for the MobileRSS-APP.
Things to bear in mind:
This isn't the default way a table view works. You might get your app rejected by apple. A table view is meant to work by clicking.
You could probably replicate the functionality without using a scroll view using touches methods and the navigation controller. A good tutorial describing how to detect swipes on your view is here: http://www.dosomethinghere.com/2009/07/23/simple-swipe-detection-in-the-iphone-sdk/
In the last method in that tutorial where there is the NSLog("swipe right") you could replace that with [self.navigationController popViewControllerAnimated:YES] which would replicate pressing the "back" button in the navigation bar.
I don't know what you could do for swipe left though..... if you wanted to do this on the table view you'll have to do some complicated maths determining how far the table view has been scrolled. Or you could test for touch events on the cells themselves, but thats something you wil have to look into. :)

UIWebView user interaction (click) delay

whenever I make a tap action on a UIWebView, for example clicking a link, there is a slightly delay between the tap and the actual highlighting / activating of the link.
Is there a way to disable this delay?
I've read that this would be possible in UIScrollView with
setDelaysContentTouches:NO
Is this also possible in UIWebViews?
This is the solution I used:
http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone
In iOS5 the UIScrollView belonging to a UIWebView has been exposed so that you can change its behavior. So to remove the click delays you can simply do:
[webView.scrollView setDelaysContentTouches:NO]
As a bonus, you can make the scrolling in a UIWebView feel a bit more native by changing the decelerationRate:
[webView.scrollView setDecelerationRate:UIScrollViewDecelerationRateNormal]

How to create a full-screen modal status display on iPhone?

I'm trying to create a modal status indicator display for an iPhone app, and would like one similar to this one used in Tweetie:
Specifically, this one "shades out" the entire screen, including the toolbar. I don't believe through any normal UIView manipulation, I can extend past the bounds of my window, can I? I believe I've seen a status indicator like this somewhere else on iPhone, possibly when I added an Exchange e-mail account.
I've tried subclassing UIAlertView and overriding its drawRect method. If I don't call [super drawRect:] it doesn't ever display the normal UIAlertView text box, however my drawing rectangle is in an odd size and position.
Anyone have any advice to accomplish this?
Check out MBProgressHUD.
Take a look at the source code to the WordPress application. They have code which you can basically drag and drop into your application to do this.
http://iphone.wordpress.org/development/
I haven't done this myself, but you could layer a UIView at the top of the view hierarchy, and use setHidden to dynamically show or hide it. Since it's at the top of the stack, it should be able to intercept all touch events.

UIWebView with UISearchBar for searching

I'm displaying a UISearchBar at the top of a UIWebView for entering information that I use to display content in the UIWebView. Is there a way to attach the UISearchBar (or perhaps a UITextField?) to the UIWebView "header" so that when the user scrolls down on the webview the UISearchBar also scrolls out of view and the full window is able to display text?
If this is not possible, how else could I accomplish this while still using the UIWebView for it's inherent text formatting capabilities?
You may try containing the UIWebView and UISearchBar within a UIScrollView. That is, create a controller that has the main view as a UIScrollView and then add in the UISearchBar and UIWebView as subviews. If you want custom behavior when you're scrolling you may have to override the event callbacks for scrolling. I haven't tried this but in theory you could have it so that when you get a scroll down and the UISearchBar is in view, you hide it up to a certain # of pixels until the UISearchBar is hidden. Afterwards you forward the scroll request to the UIWebView so it can deal with things. Basically have a middleman that delegates the scroll events as necessary.