I want to insert in my app a startup animation, after the default image disappears. In my app, I have a navigation bar and a tab bar, so I have tried to put this in the view did load:
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myIMG.png"]];
[self.view addSubview:img];
Then, I want to animate that image with a transition, but with the image I positioned in the view, between the tab bar and the nav bar, and I want the the image in front of all to start the animation. How can I do this?
You should:
Create a view controller named startup view controller.
In AppDelegate when app start, set this view is rootViewController
Do some animation with your image or whatever you want while loading data or connecting to server.
When everything done, from this start up view controller, you can remove this start up view and show your main view by call app delegate to set your main view controller is root view controller.
[Edit]
In case you only want the imageView can cover all the screen, then you can do as following:
[appDelegate.window addSubview:imageView];
Create View Controller for your startup animation
In App Delegate , show your startup View Controller
In AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
....
....
....
frontScreen *animScreen = [[frontScreen alloc] initWithNibName:#"frontScreen" bundle:nil];
self.window.rootViewController = animScreen;
[self.window makeKeyAndVisible];
}
After finished animation, call show tabview controller
In frontScreen.m
AppDelegate* app =(AppDelegate*)[UIApplication sharedApplication].delegate;
[app afterAnimation];
In AppDelegate.m
-(void)afterAnimation {
rootController *list=[[rootController alloc] initWithNibName:#"rootController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:list];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible]; //optional
}
//Display an Ads Imageview with animation on top of View
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sale2.jpg"]];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[imageView addGestureRecognizer:tapGesture];
[imageView setUserInteractionEnabled:YES];
[imageView setMultipleTouchEnabled:YES];
[UIView animateWithDuration:3.5 animations:^{imageView.alpha = 0;imageView.alpha = 1;}];
[self.window addSubview:imageView];
-(void)tapDetected:(UIGestureRecognizer*)recognizer{
//**************Remove the Advertising Image after the user press single tap on the img
[UIView animateWithDuration:1 animations:^{imageView.alpha = 1;imageView.alpha = 0;}];
}
Your best bet to cover everything is to create a segue of the Modal style, and fill that segue's view with your animation image, and as the app launches, programmatically call that segue right away, so it is the first thing to appear.
[self.tabBarController.view addSubview:img];
then your image will show full screen.
Related
I'm currently having a UIViewcontroller with a 3-segment UISegmentedControl that when clicked switches view controllers displayed. The navigation bar and tab bar of this view are translucent.
I initialize the view like this:
- (void)viewDidLoad {
[super viewDidLoad];
[self setAutomaticallyAdjustsScrollViewInsets:YES];
self.segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:#"View 1",#"View 2",#"View 3",nil]];
[self.segControl setTintColor:[[ConstantsSingleton sharedConstants] default_bg_Color]];
[self.segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[self.segControl addTarget:self action:#selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
[self.segControl setSelectedSegmentIndex:0];
self.navigationItem.titleView = self.segControl;
//Setting up the first viewcontroller
UIViewController *vc = [self viewControllerForSegmentIndex:self.segControl.selectedSegmentIndex];
[self addChildViewController:vc];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];
self.currentViewController = vc;
}
The contentView is a IB defined UIView with 0 leading and trailing on all sides (so basically it fills the parent view).
I switch viewcontrollers the following way:
-(void)segmentChanged:(UISegmentedControl *)sender {
UIViewController *vc = [self viewControllerForSegmentIndex:sender.selectedSegmentIndex];
[self addChildViewController:vc];
[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
vc.view.frame = self.contentView.bounds;
[self.currentViewController.view removeFromSuperview];
[self.contentView addSubview:vc.view];
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentViewController removeFromParentViewController];
self.currentViewController = vc;
}];
self.navigationItem.title = vc.title;
}
Now whenever I run this with a opaque navigation bar and tab bar this works fine, but whenever I try to use a translucent navigation bar and/or tab bar only the first view gets resized/its insets adjusted properly to not be behind the translucent navigation bar and/or tab bar. The second and third view will still appear behind them when they appear on screen.
It doesn't matter which viewcontroller is set as the first viewcontroller, all lead to the same behaviour.
What could be causing this issue and is there a way to solve this without resolving to manual contentinset adjustments.
I would suggest to enable the option Extend Edges in the property inspector of you're view.
Here's a good stackoverflow post differentiating the various layout settings for iOS 7 and up:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7
I am making application in Ipad i have taken one pickerviewController in Xib and i show it when user click on particular button now i am trying to put that picker view in popover
this is how i am trying to achieve this tast
pickerView.hidden=FALSE;
i have created outlet of picker and i unhide it here
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];
[popoverView addSubview:pickerView];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);
//create a popover controller
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect;
popoverRect.origin.x =323;
popoverRect.origin.y = 713;
popoverRect.size.height = 215;
popoverRect.size.width = 70;
[popoverController presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
now the Issue Is that my popover is displaying but it is totally black I am struggling on this please tell me what am i doing wrong or correct the code thank you for help
Seems your picker view is hidden somewhere in the pop over because the frame is not properly set yet. So try to set the frame of the picker view to be equal to the bounds of the pop over as a starting point:
pickerView.frame = popoverView.bounds;
But before adding the picker view as a subview in the pop over, you need to remove the picker view properly from the superview.
Now, by default Xcode will generate the IBOutlet as weak property, and this will cause the picker view to be deallocated when it is removed from the superview. So you will need to declare the picker view as a strong property first.
After that, you can remove it from the current superview:
[pickerView removeFromSuperview];
You should keep a reference to the pop over view controller, for example declaring it is a property, and call dismissPopoverAnimated to dismiss the pop over properly.
I managed to successfully change some of my UIView background to a custom image using
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"myCustomBackground.jpg"]];
But it does not work on a particular view in a controller that is presented modally as such,
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
navController.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:navController animated:NO];
[loginViewController release];
[navController release];
It seems like self.view inside this controller is behind the view it was showing.
EDIT
LoginViewController.m
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"myCustomBackground.jpg"]];
}
self.view in this case seems to be hidden behind the current view that it's displaying. I did not add any subView beforehand.
As you mentioned in your comments, your view contains UIScrollView, UILabel and UIButton.
You should set to all this subviews property backgroundColor = [UIColor clearColor];. Hopefully that would help.
If you are editing subview in IB then you should find property Background in Attributes Inspector and select Clear Color (for all subviews).
I am new bee in iPhone. I have implmented using some tutorials, a Splash Screen before loading the UIViewController. Now i want to implement a NavigationController in my application and want to display a Splash Screen before it. Since I am new in Iphone so i did not get any tutotrials or guides to make a Splash Screen before loading a Root Navigation Controller.
I have seen many methods in which they over write the Default.png file and so on. I dont want to implement that one. I want a sperate UIView to have my custom Images and text in it and display that UI View as a Splash Screen
can anybody Guide me please.
Thanks in advance
Here you go buddy. Have fun and happy coding....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Add a splash screen
UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splash.png"]];
imgv.userInteractionEnabled = YES;
[navigationController.view addSubview:imgv];
[imgv release];
[self performSelector:#selector(removeSplash:) withObject:imgv afterDelay:3.0];
[window addSubview:navigationController.view];
return YES;
}
- (void)removeSplash:(UIImageView *)imageView {
[imageView removeFromSuperview];
}
Use "self.window" to display the splash image first. If u simply write "window", the image will not be displayed and animated in the first view, since the image can't be directly linked to the window in that case. Write the following code in appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"themes.png"]];
imgv.userInteractionEnabled = YES;
[self.navigationController.view addSubview:imgv];
//[imgv release]; If you don't use ARC, uncomment this.
[self performSelector:#selector(removeSplash:) withObject:imgv afterDelay:3.0];
[self.window addSubview:self.navigationController.view];
return YES;
}
- (void)removeSplash:(UIImageView *)imageView
{
[imageView removeFromSuperview];
}
I want to show the subview of a view in popover.
To elaborate,
I have a mainViewController.
I hava a subview 'songListView' in this mainViewController.
I have a button titled 'list' in the mainViewController' itself.
I want to show the songListView in popover on clicking the button 'list'.
So, how should I do this.
You could use the below code as a reference for showing PopOver from a UIButton
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
My problem is solved.
I just created another View Controller class, i.e. 'TempPopoverView'.
Then I set the view of this TempPopoverView equal to the subview of my MainView
Here is the code snippet from my code:
TempPopoverView *viewController = [[TempPopoverView alloc]initWithNibName:#"TempPopoverView" bundle:nil];
[self. songListView setHidden:NO];//songListView is subview of MainView
viewController.view=self. songListView;
UINavigationController *navCont = [[UINavigationController alloc]initWithRootViewController:viewController];
navCont.navigationBar.tintColor = [UIColor colorWithRed:.102 green:.102 blue:.102 alpha:1];
[self showPopOverController:navCont andFrame:sender.frame andInView:self.view];//self.view is the MainView
[viewController release];
[navCont release];
U can use presentModalViewController on your main view.
For example
SongListView *songList = [[SongListView alloc] init];
[self presentModalViewController: songList animated: YES];
There are different animations possible as well.
as simple as you think to add subview in self.view
[popoverController.contentViewController.view addSubview:yourselfobject];