Xcode Objective-C Mac: How to place object on top of AVPlayerView? - objective-c

I'm currently working on a game. It plays a movie and the story changes depending on the players actions. I'm using quick time events (press a button in x seconds). When there's a quick time event I want to show the button that has to be pressed and the time left to press that button.
I play the movie(s) using an AVPlayerView. On top of that AVPlayerView I have placed a label. But the label is always invisible. It's because of the AVPlayerView.
So does anyone know a way around this?
Edit
I didn't use any code to place the label on top of the AVPlayerView. I just placed it there in the MainMenu.xib. When I view it in Xcode it looks like this:
But when I run the application it looks like this:
As you can see in the first image, all objects are under "View" and the label appears lower in the list so it should be on top of the AVPlayerView. Xcode displays the label on top of the AVPlayerView (image 1), but when I run the application the label is underneath the AVPlayerView (image 2). So my question was how to display the label on top of the AVPlayerView.
I hope this is enough information ;)

Link your label to an IBOutlet in the ViewController which describes your view and in the viewDidLoad() method write
/*top of your file*/
#property (strong, nonatomic) IBOutlet UILabel *myLabel;
/* other properties */
#implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
/*code*/
[self.view bringSubviewToFront:myLabel];
}
/*rest of your code*/
This should do the trick for you.

Related

Open 3 views on 3 buttons

I have 3 buttons on same page but those buttons are calling 3 different views on
click.Like button1 opens view1,button2 open view2 and button3 open view3.but i want all
those buttons on upside of view like tab bar is having downside.I tried by creating or
calling views on button click but on every click it's creating new object of view which i
don't want..Please help me to solve this issue.Is there any other way to solve this
problem. I tried segment too but not working.
I'm not quite sure, if this is what you really want.
The view would be larger than it actually requires to be, regarding your screenshot?
Why don't you just set the views size to match the size of the view that is below your three buttons.
In case the entire ViewControllers' view is of height: 524px
substracting the orange bar and the buttons: around 450px
Now just create the view from your buttons click action with the exact frame size, as your tableview and add it to the view as subview?
If another button is clicked, remove this view again and add the new view?
So in case you got this in one single ViewController, which I guess:
Simply change the following for your buttons:
So, in case you got the following 3 buttons
#property (weak, nonatomic) IBOutlet UIButton *buttonA;
#property (weak, nonatomic) IBOutlet UIButton *buttonB;
#property (weak, nonatomic) IBOutlet UIButton *buttonC;
Implement the function, which reacts on these three button events:
- (IBAction)myButtonAction:(UIButton *)sender
{
UIViewController *viewControllerToDisplay;
// Load UIViewController for its view from your .xib-file:
// Alternatively you could do this with switch.case and checking a button's tag-values, but I think is easier to read
if (sender == self.buttonA) viewControllerToDisplay = [ViewControllerA new];
else if (sender == self.buttonB) viewControllerToDisplay = [ViewControllerB new];
else if (sender == self.buttonC) viewControllerToDisplay = [ViewControllerC new];
// Only display the view, if the viewController was created
if (viewControllerToDisplay)
{
viewControllerToDisplay.view.frame = self.tableView.frame;
[self.view addSubview:viewControllerToDisplay];
}
}

uibutton hide and dropdown text

I have a signup button that switches screens for a signup form. I'd like for it to hide the button and drop down text boxes beneath when the button is tapped (instead of switching screens). Is this possible? Currently I have in my .h file...
#property (nonatomic, strong) IBOutlet UIButton *emailSignUp;
- (IBAction)hideButton:(id)sender;
and in the .m file my method is as follows
- (IBAction)hideButton:(id)sender {
[self.emailSignUp setHidden:YES];
}
However it seems to be crashing whenever I try to test. Any advice? I thank you guys in advance. I know there is a long way to go, but I feel this is my first step.
It sounds like you haven't connected the button you created in the Interface Builder portion of Xcode to the emailSignUp IBOutlet. You can do this by going to the Interface Builder, selecting File's Owner and then the Connection Navigator (in the right side panel, designated by the arrow icon in the tab bar). Then, drag from the Outlet to the button.

In Xcode, make a button look like a text field or a textfield look like a button

In Xcode (iOS), I have a screen with a combination of buttons and text fields. However, they look different. Is there a way that I can have a button look like a textfield? Or is there a way I can make a textfield act like a button (perform some action when pressed and don't bring up the keyboard)?
Thanks
You can try one of these:
place a transparent (custom with no image) button on top of the text field and attach the desired action to it
show your view in the implementation of the textFieldShouldBeginEditing: UITextFieldDelegate protocol method
Subclassing is also an option, but it will probably complicate your task too much.
If You want to perform an action and do not bring up the keyboard when pressed on UITextField You can do it like this:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// do here everything you want
NSLog(#"Pressed on TextField!");
[self.view endEditing:YES]; // Hide keyboard
return NO;
}
This function will be called every time when pressed on textField.
** Don't forget to delegate UITextField.
Note: With this You will face the problem: if keyboard is shown it will not hide, so You need also add -endEditing:YES.
You need to custom one of them ... or both
Exemple : create a class CustomTextField : UITextField
in this class use :
#import <QuartzCore/QuartzCore.h>
Play with style
Late answer, but nevertheless. I did this to make a UIButton look like a UITextField
#property (weak, nonatomic) IBOutlet UIButton *resolutionButton;
And in viewDidLoad:
dispatch_async(dispatch_get_main_queue(), ^{
[[self.resolutionButton layer] setBorderColor: [UIColor colorWithWhite:0.6f alpha:0.6f].CGColor];
self.resolutionButton.layer.cornerRadius = 5.0f;
self.resolutionButton.layer.borderWidth = 0.5f;
}

Referencing an array of IBOutlet 's (NSButton)

I am making an application where there are 32 Check Box, and a NSTextField.
If the user clicks on the NSTextField the buttons shall assume the value that describes the binary rappresentation of this number.
No problem receiving the "clicked" action on the NSTextField, but for the buttons I have declared an array of 32 NSButtons:
#import <Foundation/Foundation.h>
#interface Handler : NSObject
{
#private
IBOutlet NSTextField* textField;
IBOutlet NSButton* bits[32]; // here are the buttons
}
- (void)awakeFromNib;
- (void) setTextField : (int) value;
- (int) getTextField;
#end
But when I try to link a Check Box with the IBOutlet "bits", I can't do it for each member.
So I can only make that array of 32 pointers to NSButton to one box.
I also show an image:
This is a problem for me, do I have to manually declare 32 different outlets with 32 different names?
You do not have to use 32 different IBOutlet references. You can declare an IBOutletCollection:
#property (retain, nonatomic) IBOutletCollection(NSButton) NSArray *buttons;
Use this to link them all up. Keep in mind that the order of the buttons is non-deterministic at runtime, meaning, you cannot guarantee that the buttons will be in any specific order when the app is running.
This is probably a good example of using an NSMatrix object.
You can add one button to your interface and then with the button selected in Xcode 4 go to Editor > Embed In > Matrix. Then you can option drag on a corner of the button to expand it into a matrix.
NSMatrix allows you to retrieve the cell values by searching for a given tag or by column/row coordinates.
HOW TO:
1) Embedding the NSButton object:
2) Option-Drag any of the button corners to expand the matrix:
I expanded it into a matrix.But graphically it looks like a single button.
This is what I get:

XIB Displaying SubComponent

I created a custom view, which has one button and one text field , as given below
#interface CommUICustomSignInView : CommUICustomView {
IBOutlet NSButton *pBtn;
IBOutlet NSTextField *pTextField;
NSTrackingArea *pTrackingArea;
NSCursor *pPonitHandCursor;
}
#property (nonatomic,retain)IBOutlet NSButton *pBtn;
#property (nonatomic,retain)IBOutlet NSTextField *pTextField;
All items are linked properly, with the view,
In Another window controller XIB, i have added one tab view, in one of the tab item view, i am going to add this view,
added one tab view and assigning this view as below,
NSTabViewItem *pTabViewItem = [pTabView tabViewItemAtIndex:0];
if(pOfflineCTlist == nil){
pOfflineCTlist = [[CommUIOfflineCTlist alloc]
initWithNibName:#"CommUIOfflineViewController" bundle:nil];
}
[pTabViewItem setView : [pOfflineCTlist view]];
[pTabView selectTabViewItemAtIndex:0];
Now with that, i could able to track the mouse event in customSignInview, in nstrackregion,
but i couldn't see the other controls, sign-in button and text field,
Am i doing something wrong,
Finally i found following way to do this,
1 -- Created a Resource like Button / text field in the Main view,
2 -- Put them over the custom view,
3 -- Link them with the custom view,
now i could able to see it,
Is there any other approach then please suggest me,