Strange things are happening here. Im working on a project which has a tableviewcontroller. The headersview are from a custom class which add a progressview and a button. When the button is clicked the progressview shows the download status en removes itself from the screen when done. Here is the problem.
The progressview isn't showing nor is it showing its progress (blue color). When I set the backgroundcolor to black I do see a black bar with no progress. Even when I set the progress to a static 0.5f.
Im also working with revealapp which shows the progressviews frame but not the trackingbar.
So the progressview is physically there but just not visible. Does anybody know why?
Structure:
Header.m
init:
[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]
layoutSubviews:
CGRectMake(x, x, x, x);
Then:
- (void)synchMedia
{
// add progressview to view
[self performSelectorInBackground:#selector(synchMediaThread) withObject:nil];
}
- (void)synchMediaThread
{
// Do all the heavy lifting
// set progressview progress
// loop this:
[self performSelectorOnMainThread:#selector(updateProgressView:) withObject:progress waitUntilDone:YES];
// finally
[self performSelectorOnMainThread:#selector(synchDone:) withObject:#(numFailed) waitUntilDone:YES];
}
When done:
- (void)synchDone {
// remove progressview
[tableview reloadData];
}
Have you downloading any large data? If so then in that case updation on UI get blocked as main thread get busy.
To check this just add NSLog statement in a function which is calculating the progress of downloading. in this case it will log the progress on console but not on UI. If you get the correct progress on console then it is sure that UI updation is blocking when you start downloading.
Try to use some delay to update the UI or
dispatch_async(dispatch_get_main_queue(), ^{
//do you code for UI updation
});
The problem was with the way the UIView was used in the tableview delegate.
Related
I'm attempting to save a thumbnail of a mapview when a user taps save when an annotation has been selected. The problem occurs when the user has not zoomed in on that annotation yet, so the close zoom level has not been loaded.
This is what I'm doing after the user taps save:
Set a bool "saving" to true
Center and zoom in on the annotation (no animation)
When the mapViewDidFinishLoadingMap delegate method gets called, and if saving is true:
Create an UIImage out of the view, and save it. Dismiss modal view.
However when the image is saved, and the view is dismissed the result image saved actually has not finished loading, as I still see an unloaded map with gridlines as shown below:
My question is, how can I ensure the map is finished loading AND finished displaying before I save this thumbnail?
Update: iOS7 has a new delegate which may have fixed this problem. I have not confirmed one way or the other yet.
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered
Pre iOS6 support:
mapViewDidFinishLoadingMap: appears to be unreliable. I notice that it is sometimes not called at all, especially if the map tiles are already cached, and sometimes it is called multiple times.
I notice that when it is called multiple times the last call will render correctly. So I think you can get this to work if you set up a 2 second timer after the user taps save. Disable interactions so that nothing else can happen, and enable user interactions when the timer goes.
If mapViewDidFinishLoadingMap gets called reset the timer again for 2 seconds in the future. When the timer finally goes off, get the snapshot of the map and it should be correct.
You will also want to consider the other callbacks such as mapViewDidFailLoadingMap. Also test this on a noisy connection, since 2 seconds may not be long enough if it takes a long time to fetch the tiles.
- (void)restartTimer
{
[self.finishLoadingTimer invalidate];
self.finishLoadingTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:#selector(mapLoadingIsFinished)
userInfo:nil
repeats:NO];
}
- (void)userClickedSave
{
assert(self.saving == NO);
if (self.saving == NO) {
self.saving = YES;
assert(self.finishLoadingTimer == nil);
self.view.userInteractionEnabled = NO;
[self restartTimer];
}
}
- (void)mapLoadingIsFinished
{
self.finishLoadingTimer = nil;
[self doSnapshotSequence];
self.saving = NO;
self.view.userInteractionEnabled = YES;
}
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
if (self.saving) {
[self restartTimer];
}
}
If developing for iOS7 the best delegate to use is: mapViewDidFinishRenderingMap:fullyRendered:
mapViewDidFinishRenderingMap:fullyRendered
Are you sure the area where you are taking the screenshot has the Zoom Level supported which you are applying. For example, in US zoom level support is higher, you can zoom in to the maximum detail, while in Asia may be a high zoom level might not be supported.
I'm new to iOS development so please bear with me.
I'm making a photo-grid using a table view and scroll view.
My question is how could I load an activity indicator until an image downloads from a server and then display the image and remove the activity indicator?
I'm trying to stay away from third-party library's as I want to understand how it works.
Place an Activity Indicator (via Interface Builder or manually) on your view. Set the property to "hide when not animating".
When doing server call, call [activityIndicator startAnimating] (IBOutlet property).
When returning with actual image, call [activityIndicator stopAnimating]. When stopping, it wil automatically hide.
You can also use the activity indicator in the iPhon/Pad status bar. To do this, use [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
Set to NO for hiding it ... (obviously)
Take a look at dowloading an image async for a sample of dl'ing an image.
You would stop the activity indicator in the didReceiveData function.
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCsQFjAA&url=https%3A%2F%2Fgithub.com%2Fjakemarsh%2FJMImageCache&ei=UEp7U_W2GoWB8gWShIGgBQ&usg=AFQjCNEc0a59K2wEOlZ2IbapWhVc87kHmg&bvm=bv.67229260,d.dGc
here you could find JMImage cache files that you could use for downloading images.
You have to change UIImageView+JMImageCache.m file
if(i) {
dispatch_async(dispatch_get_main_queue(), ^{
safeSelf.jm_imageURL = nil;
safeSelf.image = i;
[safeSelf setNeedsLayout];
[safeSelf setNeedsDisplay];
if (completionBlock) {
completionBlock(i).
}
});
then use method
enter code here
{
[yourImageView setImageWithURL:[NSURL URLWithString:urlString] placeholder:[UIImage imageNamed:#"placeholder"] completionBlock:^(UIImage *image)
{
// remove added activity indicator here
}failureBlock:^(NSURLRequest *req,NSURLResponse *resp,NSError *error)
{
// show error message
}];
}
so here is the deal:
I have a label (NSTextField) that I want to activate after I click a button. This label will appear while the program is loading some wavs (since it usually makes a minor delay when it does). I then want it gone once this has happened (and the new View appears).
Now, the problem I have is that this update does not seem to happen when I tried this. If I don't make it disappear at the end then I can see it, but only after the delay has occured (rendering it pointless).
Currently I am using:
[label2 setHidden:NO];
I understand that this will occur once the method I called it in has finished (which is a problem). Any idea what I could do instead so that the label is shown while the program is loading wavs?
Thanks heaps!!
Ok, I guess I solved it myself - I hope this helps people.
So when I click the button I disable the buttons and replace the label temporarily. This, however, only happens in the next view (so I'm not sure how to make it occur in the same view).
I disable the buttons for about 1 second, and it is here that the label is shown.
Here's some code to show what I mean:
- (IBAction)clickedTheButton:(id)sender {
[button setEnabled:NO];
[label2 setHidden:NO];
...
//Changes the View
[self nextMethod];
}
The View has now changed, and this method is called next. This enables me to see the label.
-(void)nextMethod{
...
[self performSelector:#selector(delayedDisplay:)
withObject:#"Hi"
afterDelay:1.0]; //delay for 1 second
}
This method then puts them back to their original state (so the label is hidden and the button is activated again)
-(void) delayedDisplay:(NSString *)string{
[button setEnabled:YES];
[label2 setHidden:YES];
}
I am trying to add a UIButton to the view of a MPMoviePlayerController along with the standard controls. The button appears over the video and works as expected receiving touch events, but I would like to have it fade in and out with the standard controls in response to user touches.
I know I could accomplish this by rolling my own custom player controls, but it seems silly since I am just trying to add one button.
EDIT
If you recursively traverse the view hierarchy of the MPMoviePlayerController's view eventually you will come to a view class called MPInlineVideoOverlay. You can add any additional controls easily to this view to achieve the auto fade in/out behavior.
There are a few gotchas though, it can sometimes take awhile (up to a second in my experience) after you have created the MPMoviePlayerController and added it to a view before it has initialized fully and created it's MPInlineVideoOverlay layer. Because of this I had to create an instance variable called controlView in the code below because sometimes it doesn't exist when this code runs. This is why I have the last bit of code where the function calls itself again in 0.1 seconds if it isn't found. I couldn't notice any delay in the button appearing on my interface despite this delay.
-(void)setupAdditionalControls {
//Call after you have initialized your MPMoviePlayerController (probably viewDidLoad)
controlView = nil;
[self recursiveViewTraversal:movie.view counter:0];
//check to see if we found it, if we didn't we need to do it again in 0.1 seconds
if(controlView) {
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[controlView addSubview:backButton];
} else {
[self performSelector:#selector(setupAdditionalControls) withObject:nil afterDelay:0.1];
}
}
-(void)recursiveViewTraversal:(UIView*)view counter:(int)counter {
NSLog(#"Depth %d - %#", counter, view); //For debug
if([view isKindOfClass:NSClassFromString(#"MPInlineVideoOverlay")]) {
//Add any additional controls you want to have fade with the standard controls here
controlView = view;
} else {
for(UIView *child in [view subviews]) {
[self recursiveViewTraversal:child counter:counter+1];
}
}
}
It isn't the best solution, but I am posting it in case someone else is trying to do the same thing. If Apple was to change the view structure or class names internal to the control overlay it would break. I am also assuming you aren't playing the video full screen (although you can play it fullscreen with embeded controls). I also had to disable the fullscreen button using the technique described here because the MPInlineVideoOverlay view gets removed and released when it is pressed: iPad MPMoviePlayerController - Disable Fullscreen
Calling setupAdditionalControls when you receive the fullscreen notifications described above will re-add your additional controls to the UI.
Would love a more elegant solution if anyone can suggest something other than this hackery I have come up with.
My solution to the same problem was:
Add the button as a child of the MPMoviePlayerController's view;
fade the button in and out using animation of its alpha property, with the proper durations;
handle the player controller's touchesBegan, and use that to toggle the button's visibility (using its alpha);
use a timer to determine when to hide the button again.
By trial-and-error, I determined that the durations that matched the (current) iOS ones are:
fade in: 0.1s
fade out: 0.2s
duration on screen: 5.0s (extend that each time the view is touched)
Of course this is still fragile; if the built-in delays change, mine will look wrong, but the code will still run.
I'm making an iPhone App which involves balloons (UIImageViews) being spawned from the bottom of the screen and moving up to the top of the screen.
The aim is to have the UIImageViews set up so that a tap gesture on a balloon causes the balloons to be removed from the screen.
I have set up the GestureRecognizer and taps are being recognized.
The problem I am having is that the animation method I am using does not provide information about where the balloon is being drawn at a specific point in time, and treats it as already having reached the final point mentioned.
This causes the problem of the taps being recognized only at the top of the screen(which is the balloon's final destination).
I have pasted my code for animation here:
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:2.0 delay:0.0 options:options animations:^{
balloonImageView.center = p;
} completion:^(BOOL finished) {
if (finished) {
balloonImageView.hidden= TRUE;
balloonImageView.image=nil;
}
I keep track of where an image is by giving a unique tag to a UIImageView and checking if gesture.view.tag = anyBalloonObject.tag and if it does I destroy the balloon.
My basic question is, is there another animation tool I can use? I understand that I can set a balloon's finish point to slightly higher than where it is on screen until it reaches the top but that seems like it is very taxing on memory.
Do you have any recommendations? I looked through the Core Animation reference, and didn't find any methods that suited my needs.
In addition will the Multi-threading aspects of UIViewAnimation affect the accuracy of the tap system?
Thank You,
Vik
You shouldnt animate game-objects (objects you interact with while they are moving) like that.
You should rather use a NSTimer to move the ballons.
-(void)viewDidLoad {
//Set up a timer to run the update-function
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(update) userInfo:NULL repeats:YES];
}
-(void) update {
for (int i = [balloonArray count] - 1; i >= 0; i--) { //Loop through an array containing all your balloons.
UIImageView *aBalloon = [balloonArray objectAtIndex:i]; //Select balloon at the current loop index
aBallon.center = CGPointMake(aBallon.center.x, aBalloon.center.y + 1); //Change the center of that balloon, in this case: make it go upwards.
}
}
Here is what you need to declare in .h:
NSTimer *timer;
NSMutableArray *ballonArray;
//You should use properties on these also..
You will have to create a spawn method which adds balloons to the screen AND to the array.
When you have done that, it's simple to implement the touch methods, You can just loop trough the balloons and check:
//You need an excact copy of the loop from earlier around this if statement!
If (CGRectContainsPoint(aBalloon.frame, touchlocation)) { //you can do your own tap detection here inthe if-statement
//pop the balloon and remove it from the array!
}
Hope that isnt too scary-looking, good luck.