background:
legacy iOS sdk 4.5 app
tab bar controller with 2 tabs
UIScrollView to display image on first tab
When first tab is displayed at startup, UIScrollView is created and image is added as subview. With iOS < 7, image is displayed. With iOS 7, image is not displayed until I click on second tab, then go back to first tab. It doesn't work when I change tab programmatically.
Did someone encounter the same issue? How to solve it...
EDIT:
scrollview is created programmatically :
scrollView = [[UIScrollView alloc] initWithFrame:frame];
problem occurs even if I create the frame after clicking a button (so, not in viewDidLoad nor applicationDidFinishLaunching)
I set minimum/maximum zoom scale, zoom scale, content offset
I add image in scrollview :
UIImageView* imageView = [[UIImageView alloc] initWithImage:newImage];
[scrollView addSubview:imageView];
scrollview is added to the view:
[self
performSelectorOnMainThread:#selector(xxxx:)
withObject:scrollView waitUntilDone:YES];
where xxxx do: [self.view addSubview:v];
Related
Am developing an iPhone App. When the user taps a button, displaying a semi-transparent UIImageView on a page (i.e. covering the whole page). Now, since the UIImageView is semi-transparent, the buttons beneath it are seen. Clicking on the buttons (though the UIImageView is on top of it) is causing the button-click to be processed ; but I want to stop this. When the UIImageView is on th e top, only touching UIImageView (which calls a method) should work ; touching anything beneath it shouldn't.
Suppose yourImageView is your UIImageView above your button, do this,
[yourImageView setUserInteractionEnabled:YES];
You have following alternatives :
First make sure that UIImageView is on top of button. Bring if front by using bringSubviewToFront
You can disable userInteraction of UIImageView.
If you have any action associated with UIImageView , then you can prefer UIButton over there instead of UIImageView and set your image as a background of UIButton , and add action you required to perform with this button.
your_semi_transparent_ImageView.userInteractionEnabled = YES;
You can add a UIView on the click of a button and then add UIImageview as a subview of view. Then decrease the alpha of uiview.
It would be better if you will add your semi-transparent imageView not to self.view but to your application's window. like this:
AppDelegate *delegate = (Appdelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window addSubview:yourImageView];
To remove yourImageView just use
[yourImageView removeFromSuperView];
Hide and disable the buttons when the ImageView is shown:
[button setEnabled:NO]; // If you want the button not to respond
[button setHidden:YES]; // If you want the button not to be seen
I'm very new to iOS programming.
I'm trying to set the toolbar background to a custom image.
I'm also using storyboards.
How do I go about that?
Do I edit UIToolbar in the UI Kit framework? Do I need to change something in Storyboard?
Thanks,
You can use UIToolbar's built-in -setBackgroundImage:forToolbarPosition:barMetrics: method:
// portrait
[yourToolbar setBackgroundImage:[UIImage imageNamed:#"YourToolbarBkg-Portrait.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
// landscape
[yourToolbar setBackgroundImage:[UIImage imageNamed:#"YourToolbarBkg-Landscape.png"] forToolbarPosition:UIToolbarPositionAny barMetrics: UIBarMetricsLandscapePhone];
YourToolbarBkg-Portrait.png will be 320x44 bkg image for portrait mode
YourToolbarBkg-Landscape.png will be 480x32 bkg image for landscape mode.
UIToolbar inherits from UIView. This just worked for me:
[topBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:BAR_BKG_IMG]] autorelease] atIndex:0];
UPDATED
topBar ------ is the outlet of the UIToolBar u are using
use this code where u are creating ur UIToolBar the class which implements the UIToolbar..
plus tell me y r u using Toolbar whats ur main purpose for it
Instead of editing UIToolBar, why not create a UIView of the same size and skin that however you would like? That would be easier if you are new.
Or if you want to override UIToolbar:
#implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: #"image.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
#end
Had a right faff with background images for ToolBars and NavBars. I know setting the background image of a NavBar and ToolBar is generally a doddle. But, when you're presenting modal VC's, for some insane reason, where a NavBar is being added and you DO change the background image, it appears to double in size. Altering the height has strange results.
My issue was where I was using a NavController all over my App, but needed a modal view for one or two aspects of it. Simple enough. However, I needed either a NavBar or ToolBar type header with a Done button to pop the VC off the stack. Again, not an issue. But I needed the NavBar or ToolBar to look the same as everywhere else in my App.
I settled on a ToolBar, seeing as the VC was being presented modally. So, there my ToolBar sat, in typical Apple-blue. Nice, but not how the rest of my App looked, where a blackened image was being used for each NavBar. Using the iOS 5 appearance proxy, I altered the background image of the ToolBar. And this worked. But, unless I had the UIImage in exactly the proportions and size expected by the Tool Bar, I was in a pickle. The image simply did not look right at all. So, I decided to create a UIIMageView, where I could control the content mode, then insert a subview onto the toolBar.
Take a look at my code below.
UIImageView *toolbarImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:NAV_BAR_BACKGROUND]];
[toolbarImageView setFrame:[self.IBOToolBar bounds]];
[toolbarImageView setContentMode:UIViewContentModeScaleAspectFill];
[self.IBOToolBar insertSubview:toolbarImageView atIndex:1];
It's a bit of a fluff but I do hope this helps someone alter the image on their ToolBar.
NAV_BAR_BACKGROUND can be defined as follows:
#define NAV_BAR_BACKGROUND #"navBarBlackMattDarkSquare.png"
I have a UIViewController and when a button is pressed, I want a half screen view to slide up with a UIPicker in it.
I made a UIView in IB with the UIPicker along with a UIToolBar with Done/Cancel buttons.
How can I make it so that just this half view slides up and the background view is still showing but dimmed or cant be played with.
I'm using this code so far:
- (void)showModalView
{
[self.popupView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.popupView];
[UIView animateWithDuration:.2 animations:^{
[self.popupView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}
Here is a pic: http://www.box.net/shared/static/08ji4s0f6i1b8qubrtz6.png
#Jon:
METHOD-1:
Make your main view transperant by setting its alpha value to 0 and add a subview to the main view which is only half of the main screen and keep it opaque (alpha value as 1) as it would be by default.
Then simply present the view controller using present Modal View Controller.
Keep in mind that because of the transperancy you would be able to see half of the previous view, but wont be able to touch it as there is a transperant view.
METHOD-2:
Another work around is to animate a UIView which is of size half of the existing view.
Then you have to simply follow animation of the UIView.
Here as it is just a UIView that will be added as subview to existing view, you will be able to touch the rest of the screen.
So you can follow either of the methods as per your requirement.
Hope this helps you.
Here is what u need its an open source code on github TDSemiModalView having a half view date picker. Check the demo project inside the code. Here is the link.. Hope it solves your problem.
TDSemiModalClass
I have a navigation based app where a certain pushed view has a nice background image. Now this view contains a UITextView which is transparent so my background shows all over the whole view except the top which holds the navigation bar. Now when I start editing the textview I would like the for the textview and the background image to "slide" up a few pixles under the navigation bar to be more visible when the keyboard shows up (without keyboard it is centered in on the screen).
I set the background with:
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.view.backgroundColor = background;
[background release];
But this does not allow me to move it. So I guess I have to make a subview or something to get this to work. I already have the animation for the textview in place, it's just the background image I also would like to move. How can I make this happen?
Just use the UIImageView for the background...
I have an application with 3 view controllers. They are all have shouldAutoRotateToInterfaceOrientation returning YES. The first two, my main menu and my submenu both autorotate just fine. The third viewcontroller, which programatically loads a UIImageView from a jpg file in the program's bundle, will only display in portrait.
In the viewcontroller containing the image, i have this:
NSString *imageName = [NSString stringWithFormat:#"%#-00%d.jpg",setPrefix,imageNumber];
UIImageView *pictureView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
pictureView.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:pictureView];
and again, I have shouldAutoRotateToInterfaceOrientation returning YES for all orientations.
My image shows up, but is sideways, and the 0,0,1024,768 values I used to make my rectangle start from the top right corner going down, instead of starting at the top left and going across (holding in landscape). Am I missing a parameter I need to set in order to ensure the imageview shows up in landscape instead of portrait?
I don't know for sure, but I suspect the setting of pictureView.frame may not be correct. The frame can be "weird" (technical term) when adding a subview to an autorotated view. See Automatically Sizing UIView after Adding to Window.