Objective C Transparent UIViewController for Gameover Screen - ios

Information: I would like to make a little Game (Not Important what kind of game) with a little Game Over Screen.
Because i cant Upload Images, i try to Describe it.
You Play, everything is alright. Then you get Gameover. The Screen should be the Same and an Overlayer is Showing the Score (Transparent / Alpha)
Now my First Question is: Is my Solution good?
I use one UIViewController from the Storyboard
Source:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UIButton *btnTest;
}
-(IBAction)btnTestClick;
#end
ViewController.m
#import "ViewController.h"
#import "MeinGottEh.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)btnTestClick
{
self.modalPresentationStyle = UIModalPresentationCurrentContext;
MeinGottEh *sampleView = [[MeinGottEh alloc] init];
sampleView.labelText = #"High: 123";
[sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:sampleView animated:YES];
}
#end
Then the Second UIViewController (External File, not in Storyboard)
MeinGottEh.h
#import <UIKit/UIKit.h>
#interface MeinGottEh : UIViewController
{
IBOutlet UIButton *btnClose;
}
-(IBAction)btnCloseClick;
#property(nonatomic) NSString *labelText;
#end
MeinGottEh.m
#import "MeinGottEh.h"
#interface MeinGottEh ()
#end
#implementation MeinGottEh
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[btnClose setTitle:self.labelText forState:UIControlStateNormal];
}
-(void)btnCloseClick
{
[self dismissModalViewControllerAnimated:YES];
}
#end
Is this Solution to Open a Highscore Box good? If no, please tell me how to do it (I make a Research on Stackoverflow. Thats the Most Parts)
If Yes: How can i make it Transparent?
Thank you very much.

Related

Changing color of IBAction with FlatUIKit?

I am trying to changing the visual aspects of my button, however I am trying to use the FlatUIKit's button aspect, for those who don't know what that is that ok as it doesn't matter, in the example project that they provide they change the color of an IBOutlet button however it dosen't work the same with an IBAction heres their example code:
#import "ViewController.h"
#import "FUIButton.h"
#import "UIColor+FlatUI.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet FUIButton *alertViewButton;
//as you can see its a FUIButton, and I'm not sure how to use that with an IBAction
#end
#implementation ViewController
- (void)viewDidLoad
{
self.alertViewButton.buttonColor = [UIColor peterRiverColor];
self.alertViewButton.shadowColor = [UIColor silverColor];
self.alertViewButton.shadowHeight = 3.0f;
self.alertViewButton.cornerRadius = 6.0f;
self.alertViewButton.titleLabel.font = [UIFont boldFlatFontOfSize:16];
[self.alertViewButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
[self.alertViewButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
}
Heres my code this far:
my .h
#import <UIKit/UIKit.h>
#interface HomeViewController : UIViewController {
}
- (IBAction)start:(id)sender;
#end
my .m:
#import "HomeViewController.h"
#import "UIColor+FlatUI.h"
#import "FUIButton.h"
#interface HomeViewController ()
#end
#implementation HomeViewController
- (IBAction)start:(id)sender {
//this is the button i want change the appearance of.
}
I am stuck with this, the button I want to use the FUIButton color effects is the IBAction called start, any help? Thanks in advance.
Note: I am using storyboards if that makes a difference.

iOS Access parentViewController to change the State of a UIButton setSelected:YES

I have a UIButton in MainViewController.
MainViewController has a childViewContoller.
I need to access the UIButton (tcButton) property in MainViewController FROM the childViewController and set it to setSelected:YES in viewDidLoad. I have the following code in my ChildViewController.m file and it's not working.
#import "ChildViewController.h"
#import "MainViewController.h"
#import "CoreData.h"
#interface ChildViewContoller ()
#property (nonatomic, strong) CoreData *coreData;
#property (nonatomic, strong) MainViewController *mainViewController;
#end
#implementation ChildViewController
#synthesize coreData, mainViewController;
-(void)viewDidLoad
{
[super viewDidLoad];
self.managedObjectContext = [(STAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
[[(mainViewController *)self.parentViewController tcButton] setSelected:YES];
}
Your code is kind of a mess. Why are you creating a new instance of yourself in viewDidLoad? This makes no sense. If ChildViewController is truly a child view controller, then you can access the parent with self.parentViewController. You only need one line in the viewDidLoad:
-(void)viewDidLoad // Line 4
{
[[(MainViewController *)self.parentViewController tcButton] setSelected:YES]; // Line 8
}
There are several issues in your code but the main idea to perform what you want is getting a pointer to the mainViewController. There are many ways to do that but here a simple example how you can implement such thing. For instance in the initializer of the ChildViewContoller you can pass a pointer to the mainViewController:
#interface ChildViewContoller ()
#property (nonatomic, strong) MainViewController *mainViewController;
#end
#implementation ChildViewContoller
- (id)initWithMainViewController:(MainViewController *)mainViewController
{
self = [super init];
if (self)
{
_mainViewController = mainViewController;
}
return self;
}
- (void)viewDidLoad
{
[_mainViewController.tcButton setSelected:YES];
}
#end
Please not that I have not tested the code above but you can get the idea.

How do I call the 'popoverControllerDidDismissPopover' method?

I am having trouble calling the the popoverControllerDidDismissPopover method in as much as I do not know where to put it and how to call it.
I have created a popover as follows -
// SettingsViewController.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "ViewController.h"
#import "SharedData.h"
#import "PlayerPopUpVC.h"
#interface SettingsViewController : UIViewController <UITableViewDataSource, UIPopoverControllerDelegate> {
- (IBAction)popUp:(id)sender;
#property (strong, nonatomic) UIPopoverController *playerPopUpVC;
#property (strong, nonatomic) PlayerPopUpVC *popUp;
// SettingsViewController.m
#import "SettingsViewController.h"
- (IBAction)popUp:(id)sender {
UIButton *editPlayers = (UIButton *)sender;
if(self.playerPopUpVC) {
self.popUp= [[PlayerPopUpVC alloc] initWithNibName:#"PlayerPopUpVC" bundle:nil];
self.popUp=[[UIPopoverController alloc] initWithContentViewController:self.popUp];
}
[self.playerPopUpVC presentPopoverFromRect:[editPlayers frame] inView:[editPlayers superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
I know I have to set the delegate of my PopOver to self in order to call the method but cannot work out what the code is.
I have tried -
self.playerPopUpVC.delegate=self
but Xcode does not like it.
My popOver class looks like this -
// PlayerPopUpVC.h
#import <UIKit/UIKit.h>
#interface PlayerPopUpVC : UIViewController <UITableViewDataSource, UIPopoverControllerDelegate> {
}
// PlayerPopUpVC.m
#import "PlayerPopUpVC.h"
#interface PlayerPopUpVC ()
#end
- (void)viewDidLoad
{
[super viewDidLoad];
self.modalInPopover = NO;
self.contentSizeForViewInPopover = CGSizeMake(240, 400);
}
Any help would be most welcome. I have spent a week now trying to sort it.
First, you need to understand the delegate pattern, which seems that you dont fully understand yet.
The popover will be the one which will call the popoverControllerDidDismissPopover method on the delegate. You only have to implement the UIPopoverControllerDelegate protocol in your class and assign yourself as the delegate of the popover. Why do you say that XCode doesn't like it? please, provide more info.
Furthermore, you are making an incorrect assignment here:
self.popUp=[[UIPopoverController alloc] initWithContentViewController:self.popUp];
Edit: Provided more code to help with the error. Please, review the delegate pattern next time before making these questions.
Your SettingsController.m should have this instead:
- (IBAction)popUp:(id)sender {
UIButton *editPlayers = (UIButton *)sender;
if(!self.popUp) {
self.popUp= [[PlayerPopUpVC alloc] initWithNibName:#"PlayerPopUpVC" bundle:nil];
}
self.playerPopUpVC=[[UIPopoverController alloc] initWithContentViewController:self.popUp];
self.playerPopUpVC.delegate = self;
[self.playerPopUpVC presentPopoverFromRect:[editPlayers frame] inView:[editPlayers superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
// Your code here
}

CALayers and Audio

I have a CALayer with an image and I have that animates when I touch it, it works, it's great. What I want to do now is also have a sound clip that plays when you press the same image. I'm finding this tricky because the CALayer is from the UIView Class called BounceView. I created an instance of BounceView on my MainViewController. I apologize if I didn't use correct terminology. Do I need to place my audio code in my MainViewController and then use delegation to allow the BounceView to trigger a method on the MainViewController? Any help or direction is greatly appreciated.
MainViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#interface MainViewController : UIViewController <AVAudioPlayerDelegate>
#property (nonatomic, retain) IBOutlet UIView *BounceView;
#property (strong, nonatomic) AVAudioPlayer *audioPlayer;
- (IBAction)playAudio:(id)sender;
#end
MainViewController.m
#import "MainViewController.h"
#import "BounceView.h"
#interface MainViewController ()
#end
#implementation MainViewController
#synthesize BounceView;
#synthesize audioPlayer;
- (void)viewDidLoad
{
[super viewDidLoad];
//Setup the audio player
NSURL *noSoundFileURL=[NSURL fileURLWithPath:
[[NSBundle mainBundle]
pathForResource:#"InTheMood" ofType:#"mp3"]];
self.audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:noSoundFileURL error:nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)loadView
{
NSLog(#"loadView");
// Create a view
CGRect frame = [[UIScreen mainScreen] bounds];
BounceView *v = [[BounceView alloc] initWithFrame:frame];
// Set it as *the* view of this view controller
[self setView:v];
}
- (IBAction)playAudio:(id)sender {
// self.audioPlayer.delegate=self;
[self.audioPlayer play];
}
#end
BounceView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import "MainViewController.h"
#interface BounceView : UIView
{
CALayer *myLayer;
}
#end
BounceView.m
I will provide this code if requested but I don't want to overload code. Here I create new layer open (alloc init), give it size, position, create UIImage, get underlying CGImage & put it on the layer then make sublayer of the view's layer.
Again, any help is greatly appreciated.
Since BounceView is an UIView class not a UIViewController, I would let the playing audio to the MainViewController.

Return to mainview from subview

Basically I want to remove my subview when a button is pressed, here is my code, please tell me what should I add.
I have created a view based application and following are the codes:
//My file name is poo1
//This is poo1ViewController.h file
#import <UIKit/UIKit.h>
#interface poo1ViewController : UIViewController
{
IBOutlet UIButton *fl;
}
#property (nonatomic,retain) UIButton *fl;
-(IBAction) ifl:(id)sender;
#end
This is poo1ViewController.m file
#import "poo1ViewController.h"
#implementation poo1ViewController
#synthesize fl;
-(IBAction) ifl:(id) sender {
UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:#"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];
}
Now similarly I have added a UIViewController Subclass called "flip" with xib. And in flip.h I have added the below code
#import <UIKit/UIKit.h>
#interface flip : UIViewController
{
IBOutlet UIButton *bb;
}
#property (nonatomic,retain)UIButton *bb;
-(IBAction)ss:(id)sender;
#end
And in flip.m
#import "flip.h"
#implementation flip
#synthesize bb;
-(IBAction)ss:(id)sender
{
//What do I need to add here to return to previous view when button is pressed.
}
When this bb button is pressed, it should act as back button, how to implement it.
just add [self removeFromSuperview]; to your method ss:
Note however that this does not dealloc the view from the memory. It's just not showing!

Resources