Currently i am working on a iPhone Application Which is displaying video. I have used MPMoviePlayController to load the Video from the local folder.
Can we customize the Standard media player ? What i want to do is to hide all the standard elements (Play, Forward, Rewind, Done) and just to build the player with a single play button with a customized image . Can anybody help me ?
You can surely add custom controls for MPMoviePlayerController. For that first hide existing controls using, MPMovieControlStyle, set this to MPMovieControlStyleNone
Now add your custom control buttons and handle all the MoviePlayer events over there, like;
Play
Pause
Stop
Prev
Next, etc.
Or you can add your own controls like jump to this time (+10 sec, +20 sec), movie speed control (1x, 2x, ..), etc.
Hope this will be useful for you.
if you want to have any controlStyle of apple and still want to add some custom buttons on movie view. You can subclass MPMoviePlayerViewController.
Let say you have MyCustomMoviePlayerViewController as subclass of MPMoviePlayerViewController then in MyCustomMoviePlayerViewController.m
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"MyCustomButton" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview :button];
}
Related
In my application I have a button and when it is pressed, lets say "touch Up inside" another view is opened. well my question is, how can I do two actions? I mean, when I pressing the button I want something to do(like hiding the button or changing the image of the button), and when I stop pressing I want to be navigated to the another view.
Do this:
[yourbutton addTarget:self action:#selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
[yourbutton addTarget:self action:#selector(touchDown:) forControlEvents:UIControlEventTouchDown];
Now selectors are:
-(IBAction)touchUp :(id)sender{
UIButton *btn = (UIButton *)sender;
[btn setImage:yourImage forState:UIControlStateHighlighted];
}
-(IBAction)touchDown :(id)sender{
//Navigate here
}
If you want to 'do something' when 'pressing', then just hook up 'Touch Down'
The class that is the delegate for the button needs to track the state, and manage that state through the events that can occur (a state machine). Use instance variables to track the state.
When you handle the button action, the code should determine what state it is in, and make any changes necessary to move to the next state.
You can use different actions for different ControlEvents
[button addTarget:self action:#selector(action1) forControlEvents:UIControlEventTouchDown] ;
[button addTarget:self action:#selector(action2) forControlEvents:UIControlEventTouchUpInside] ;
Just add in your code to IBActions. Then like the actions through the interface builder to different touch events.
Code:
[yourUIButton addTarget:self action:#selector(touchUp:) forControlEvents:UIControlEventXXXXX];
There are a lot of events you can link your UIButton to:
UIControlEventTouchDown
UIControlEventTouchDownRepeat
UIControlEventTouchDragInside
UIControlEventTouchDragOutside
UIControlEventTouchDragEnter
UIControlEventTouchDragExit
UIControlEventTouchUpInside
UIControlEventTouchUpOutside
UIControlEventTouchCancel
Ref:UIControl Apple Reference
How do I get this effect in a UITableViewCell? The icon placement is just to the right of the label.
Also, is this shuffle icon something that is standard which I should use? I have a similar application where the user can shuffle through words, each word will play in random order if they press this.
You can use the UIKit Artwork Extractor [1] to extract all the apple standard icons and use them in your application. Apple has no problem with this (so far).
[1] https://github.com/0xced/UIKit-Artwork-Extractor/blob/master/README.md
(assuming u click that icon to shuffle the list)
its as simple as adding a custom button with that imageview as background , as subview to the cell.but set the frame accordingly like
UIButton *shuffbutton=[UIButton buttonWithType:UIButtonTypeCustom];
shuffbutton.frame=CGRectMake(100,5, 30, 30);
[shuffbutton setBackgroundImage:[UIImage imageNamed:#"shuffle_icon.png"] forState:UIControlStateNormal];
[shuffbutton addTarget:self action:#selector(shuffle:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:shuffbutton];
So I have an application that takes in images from the video camera and displays information to the screen after some processing on the image. I've added a pause button so the user can 'freeze' the most recent results on the screen.
The pause works, but it is one cycle behind. By the time the button press is recorded, the next image is already being processed so the results that are being locked on the screen are actually from the subsequent image. I've tried adding a delay to allow the user time to press pause using:
[self performSelector:#selector(waitForPause) withObject:nil afterDelay:2];
but this does not perform as I was expecting. Any ideas on how to handle this pause correctly?
EDIT: I've noticed that the AppDelegate file has some functions that appear to handle this sort of thing. Namely, applicationWillResignActive can supposedly be used to pause a game based on the apple docs. Has anyone used this for such a purpose? The method is currently empty. What would I have to add to this method to get it to temporarily pause the app based on a button press?
UPDATE: Here is how I currently implement and handle the pause button press.
//Pause Button
self.pauseButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[pauseButton addTarget:self
action:#selector(pauseButtonPress:)
forControlEvents:UIControlEventTouchDown];
[pauseButton setTitle:#"Pause" forState:UIControlStateNormal];
pauseButton.frame = CGRectMake(80.0, 100.0, 160.0, 40.0);
[self.view addSubview:pauseButton];
- (void) pauseButtonPress:(id) sender {
[pauseButton setHidden: YES];
[playButton setHidden: NO];
continueRunningScript = NO;
NSLog(#"paused");
NSLog(#"Current Result: %#", result_string);
}
Thanks.
You don't need to implement delays. Try this:
Each time you render a new image to the screen, save the old image in a previousImage variable. When the user hits the pause button, simply swap out what is currently on-screen for with the contents of previousImage.
I am creating an iPad application that behaves like a power point presentational. I am creating several slides and each slides contains several images with basic functionality. Because I am creating so many slides it will be nice if I can create the IBOutles programmatically since I place so many buttons per slide for instance. it takes a while to place those outlets and create the connections. How can I speed up this process?
Why not just create every item programmatically?
Take a UIButton for example.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Hello" forState:UIControlStateNormal];
button.frame = CGRectMake(40.0, 200.0, 170.0, 40.0);
[self.view addSubview:button];
This should be of interest to you: http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/030-Edit_User_Interfaces/edit_user_interface.html#//apple_ref/doc/uid/TP40010215-CH6-SW1
There's even a nice video tutorial if you click: "To create and connect a new outlet ..."
Good luck!
I haven't been programming on the iPhone for very long, but I'm picking it up slowly by googling problems I get. Unfortunately I haven't been able to find an answer for these.
I have started a new View-based application in Xcode 3.2.2 and immediately added the following files: myUIView.m and myUIView.h, which are subclasses of UIView. In Interface Builder, I set the subclass of the default UIView to be myUIView.
I made a button in the drawRect method.
Problem one: The title of the button only appears AFTER I click the screen, why?
Problem two: I want the button to produce the modalview - is this possible?
The code is as follow:
#import "myUIView.h"
#implementation myUIView
- (void)drawRect:(CGRect)rect {
// Drawing code
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,100,100);
[button setTitle:#"butty" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
-(void)buttonPressed:(id)sender{
NSLog(#"Button pressed");
//present modal view somehow..?
}
I can't see how to post attachments, but if anyone thinks it will help I can upload the source.
Many thanks,
Andy
drawRect: is for custom drawing. You won't often need to do that. Your button won't be drawn until it gets sent drawRect:, probably in the next iteration of the run loop (ie, when you click on the view).
If you want a button on your view, either drag it there using IB, or move the code from drawRect: to viewDidLoad.
You present a modal view from a view controller by:
[self presentModalViewController:viewController animated:YES];
Do this in the action method your button sends to your view controller. This should indicate to you that you need to take a look at your application design.