fading background while UIWebview has focus - objective-c

Is it possible to fade the background of an app (a lightbox type effect) when a UIWebView has the focus, keeping the UIWebView sharp?

Add another transparent view (to achieve the fading effect) in the superview of the webview:
[self.view addSubview:transparentView];
After that, bring the webview to the front.
[self.view bringSubviewToFront:self.webView];

Related

iOS7 UIWebView scroll indicator disappearing

I've noticed weird behaviour in my UIWebView using iOS 7.0 SDK. This behaviour wasn't there in iOS 6, and my code regarding this webview hasn't changed.
I have a storyboard, not using autolayout, autoresize mask for the webview is everything selected.
I have scale pages to fit set to YES.
When I load a local html file, it displays fine and upon scrolling, the webview will show the scroll indicator.
When I rotate the device, the webview resizes fine, it's rect is correct size, the page displays as expected, however the scroll indicator is not visible
Here's the kicker. If I don't scroll before I rotate, the scroll indicator is visible when I start scrolling AFTER the rotate.
If I DO scroll before the rotate, the scroll indicator is not visible after the rotate.
I checked the html, there is no jquery or js that will change the overflow in regards to orientation.
OK I found the solution, I was using a subclassed UIWebView and overriding the layoutSubviews to not draw the gradient shadows above and below the scrollview (as it has by default).
- (void)layoutSubviews
{
[super layoutSubviews];
// hide the shadows at the top and bottom of the webview's frame
for (UIView* shadowView in [self.scrollView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
Well guess what was a UIImageView? The Scroll Indicator! I removed this code and the problem went away

UIBarButtonItem with portrait and landscape images may show portrait image for landscape orientation

In iOS 7, I am showing a UIBarButtonItem in the navigation bar of a UINavigationController. The UIBarButtonItem has an image for portrait orientation and another image for landscape orientation:
// "self" refers to the UINavigationController
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:portraitImage landscapeImagePhone:landscapeImage style:UIBarButtonItemStylePlain target:nil action:NULL];
If you just rotate the interface, the correct image is used for the interface orientation. However, if the view for the UINavigationController first appears in landscape orientation (say, by presenting it in landscape orientation or by dismissing a view controller that is covering it up in landscape orientation), the portrait image is used instead! Why is this happening? Is this a framework bug? If so, is there a way to work around this, so the landscape image will always be shown for landscape orientation?
I'm having this same problem.
I found a solution over at UIBarButtonItem with separate portrait and landscape images - layoutSubviews not called when popping a view controller from UINavigationController that sounded really promising, but it doesn't work for me. I'm going to go with changing the image on orientation change instead. Please post your solution if you find something better.
The landscape image works all of the time on UIToolbar, but not UINavigationBar. With UINavigationBar, I get the problem you state. I also had the problem that if I tapped the button in landscape, it would change to its portrait version.

Flip vertical UIWebview to be shown when view did load

I was searching information to show a uiwebview using a flip horizontal effect like modal transition one in viewDidLoad event, but I wasn't successful, even in apple documents. Can anybody help me with that?
Many thanks
the transition to animate webView with the view add your webView like this.
[UIView transitionWithView:poster.view duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self.view addSubview:yourWebView];
}
completion:NULL];
The animation you want to add can be done on the UIView. So you should addSubView the UIWebview to the UIView and then do the animation on the UIView.

Rotating UITabBarController Icon

I have an UITabBar in my application. One of the tab bar icons looks like a loading symbol. When the user presses the loading button I want the icon to spin/rotate until the loading is done. Should I use UIImageView to animate or something else? How should I make this happen?
Jacos, unfortunately you cannot do that with the UITabBarController and manipulate the tabBarController's tabBar properties. My best bet would be that you use a UIToolBar and assign a black color and make it appear like a tabBar and have buttons added in them as a subView so that they look like tabBarItems.
Its much more customizable, and you can even provide a scrolling experience and add more buttons to it.
I know this question is 4 years old but I had the same problem and managed to fix it by reading the tutorial in here:
https://medium.com/#werry_paxman/bring-your-uitabbar-to-life-animating-uitabbaritem-images-with-swift-and-coregraphics-d3be75eb8d4d#.bjfpbdnut
The main point is to get the view for desired UITabBarItem and the get the UIImageView from it in viewDidLoad:
UIView *plusView = self.tabBar.subviews[1];
self.plusImageView = plusView.subviews.firstObject;
self.plusImageView.contentMode = UIViewContentModeCenter;
Then in didSelectItem method you can do this:
[UIView animateWithDuration:0.4 animations:^{
[self.plusImageView setTransform:CGAffineTransformMakeRotation(M_PI/4)];
}];
My code only rotate the image view for 45 degrees but you can change as you wish.
I guess you could change the UITabBarItem's icon on a timer, but that seems pretty kludgey. You would have to pre-render each frame of your "loading" icon rather than rotate an ImageView.
Another hackey solution would be to add your ImageView to the UIWindow and move it on top of the TabBarController's TabBar (adding it to the TabBar itself is asking for trouble).
You shouldn't try to animate the actual UIImageView within the UITabBarController. I would take this approach:
Set the image for the relevant tab to nil or a blank image.
Create a UIActivityIndicatorView and add it over the tab bar. Position it over the correct tab.
[self.tabBarController.tabBar addSubview:activityIndicatorView];
When your loading task has completed, restore the normal image to the tab and remove the activityIndicator from the tab bar.

Present UIView modally that nots full screen

I have a view 200 x 150 px which i would like to present on the tap of a button. If i use addSubview: then the view shows up in the correct position, but i can still tap other buttons on the superview, which is behaviour i don't want.
If i use presentModalViewController then the view takes up the whole screen, which is what i don't want either... this happens even if i set wantsFullScreenLayout to NO.
How can i present the view so that the user can only interact with controls on the presented view?
Thanks
Make the view the size of the screen (taking the status bar into account). That view should have a translucent background color (or clear). Have the 200x150 view be on the bottom of that view to have the appearance of a UIActionSheet, where the background dims and the user cannot interact with other elements on the screen.
Then, you can use presentModalViewController to present the view.
Addition
In the view controller's .m file, define awakeFromNib:
-(void)awakeFromNib
{
self.view.backgroundColor = [UIColor clearColor];
}