Rectangle 27 1

There is no way to move the status bar; it is either visible or hidden. However, you can get around this by replacing the status when the UITableView is about to be scrolled with a UIView containing a screenshot that includes the status bar.

I would start with the UIScrollViewDelegate. Since the UITableViewDelegate is a subclass of the UIScrollViewDelegate, you can, in your view controller, set your UITableView's delegate to self. With this, you can now listen to scrolling movements.

When the UITableView is at the top and the user is scrolling down, I would recommend to take a screenshot of the status bar, add it to a UIView, and move that said view up at the same speed as the UITableView is moving (see the UIScrollViewDelegate documentation for help). Likewise, when scrolling to the top, I would have the view move down to the position of the status bar, then remove the view, and set the status bar visible.

With this method, you have the appearance of the status moving up and down with the table view.

ios - How to hide status bar gradually in swift - Stack Overflow

ios swift
Rectangle 27 0

I don't think there's a universal way to do this for views. Sounds like you're stuck with scrollViewDidEndScrolling and other ScrollViewDelegate methods. But I'm not sure why you say it's elegant, they're quite straightforward.

iPhone: Howto get notified when an UIView becomes visible - Stack Over...

iphone uiview uiscrollview
Rectangle 27 0

A UIView is always a rectangular shape, you can't alter that. However, you could perhaps get the effect you want by using CALayer masking. Make a UIView and apply a custom mask to it, whereby the mask has the appropriate data in it for a triangle. Then any actual content you put in your UIView will only be visible in the appropriate 'triangle' shaped area.

To make your mask layer, you can either use an image (e.g. a png) or use core graphics to draw a triangle.

There's tons of info on this sort of stuff in the Apple Quartz 2D docs.

There's also info about this stuff in Apple's API docs for UIView and CALayer.

iphone - is it possible to make triangle UIView? - Stack Overflow

iphone objective-c cocoa-touch ipad
Rectangle 27 0

ViewWillAppear: Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).

ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.

If you want to do something when your application comes from background and go in to background do like this To get when enter background In appDelegate.

(void)applicationDidEnterBackground:(UIApplication *)application
(void)applicationWillEnterForeground:(UIApplication *)application

c# - ViewDidAppear() and ViewWillAppear() only called on launch - Stac...

c# ios iphone xamarin
Rectangle 27 0

First, add a category for UIView with the following method:

// retrieve an array containing all super views

-(NSArray *)getAllSuperviews
{
    NSMutableArray *superviews = [[NSMutableArray alloc] init];

    if(self.superview == nil) return nil;

    [superviews addObject:self.superview];
    [superviews addObjectsFromArray:[self.superview getAllSuperviews]];

    return superviews;
}

Then, in your View, check if the window-property is set:

-(void)didMoveToWindow
{
    if(self.window != nil)
        [self observeSuperviewsOnOffsetChange];
    else
        [self removeAsSuperviewObserver];
}

If it is set, we'll observe the "contentOffset" of each superview on any change. If the window is nil, we'll stop observing. You can change the keyPath to any other property, maybe "frame" if there is no UIScrollView in your superviews:

-(void)observeSuperviewsOnOffsetChange
{
    NSArray *superviews = [self getAllSuperviews];
    for (UIView *superview in superviews)
    {
        if([superview respondsToSelector:@selector(contentOffset)])
            [superview addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
    }
}

-(void)removeAsSuperviewObserver
{
    NSArray *superviews = [self getAllSuperviews];
    for (UIView *superview in superviews)
    {
        @try
        {
            [superview removeObserver:self forKeyPath:@"contentOffset"];
        }
        @catch(id exception) { }
    }
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if([keyPath isEqualToString:@"contentOffset"])
    {
        [self checkIfFrameIsVisible];
    }
}

Finally, check if the view's frame is visible inside the window's frame:

-(void)checkIfFrameIsVisible
{
    CGRect myFrameToWindow = [self.window convertRect:self.frame fromView:self];
    if(myFrameToWindow.size.width == 0 || myFrameToWindow.size.height == 0) return;
    if(CGRectContainsRect(self.window.frame, myFrameToWindow))
    {
        // We are visible, do stuff now
    }
}

Thanks for the detailed solution. I an trying it out, but the problem is that superviews are being deallocated before I have a chance to remove their observer. I am even observing changes to their "superview" key path but it does not help. This is definitely the worst part of KVO.

This should be no problem, I guess. If a superview gets deallocated, the observing view (the view of which we want to know if it is visible), should be deallocated, too, since it is a subview.

You are right. My issue was that I was failing to call removeObserver on all the key paths. That said, KVO best practice is to retain ownership of all observed objects. In this case, this means placing the list of superviews created by observeSuperviewsOnOffsetChange in a member variable, and using this retained superviews list in removeAsSuperviewObserver. This also has a slight performance benefit.

cocoa touch - How can I get notified when a UIView becomes visible? - ...

cocoa-touch uiview uiscrollview
Rectangle 27 0

- (void)viewDidLoad 
{
    [super viewDidLoad];

// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(keyboardWillShow:) 
                                             name:UIKeyboardWillShowNotification 
                                           object:self.view.window];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(keyboardWillHide:) 
                                             name:UIKeyboardWillHideNotification 
                                           object:self.view.window];
    keyboardIsShown = NO;
        //make contentSize bigger than your scrollSize (you will need to figure out for your own use case)
    CGSize scrollContentSize = CGSizeMake(320, 345);
    self.scrollView.contentSize = scrollContentSize;
    }


- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

    // unregister for keyboard notifications while not visible.
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                    name:UIKeyboardWillShowNotification 
                                                  object:nil]; 
    // unregister for keyboard notifications while not visible.
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                    name:UIKeyboardWillHideNotification 
                                                  object:nil];  

}

- (void)keyboardWillHide:(NSNotification *)n
{
    NSDictionary* userInfo = [n userInfo];

    // get the size of the keyboard
    NSValue* boundsValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
    CGSize keyboardSize = [boundsValue CGRectValue].size;


    // resize the scrollview
    CGRect viewFrame = self.scrollView.frame;
    // I'm also subtracting a constant kTabBarHeight because my UIScrollView was offset by the UITabBar so really only the portion of the keyboard that is leftover pass the UITabBar is obscuring my UIScrollView.
    viewFrame.size.height += (keyboardSize.height - kTabBarHeight);

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    // The kKeyboardAnimationDuration I am using is 0.3
    [UIView setAnimationDuration:kKeyboardAnimationDuration];
    [self.scrollView setFrame:viewFrame];
    [UIView commitAnimations];

    keyboardIsShown = NO;
}

- (void)keyboardWillShow:(NSNotification *)n
{
    // This is an ivar I'm using to ensure that we do not do the frame size adjustment on the UIScrollView if the keyboard is already shown.  This can happen if the user, after fixing editing a UITextField, scrolls the resized UIScrollView to another UITextField and attempts to edit the next UITextField.  If we were to resize the UIScrollView again, it would be disastrous.  NOTE: The keyboard notification will fire even when the keyboard is already shown.
    if (keyboardIsShown) {
        return;
    }

    NSDictionary* userInfo = [n userInfo];

    // get the size of the keyboard
    NSValue* boundsValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
    CGSize keyboardSize = [boundsValue CGRectValue].size;

    // resize the noteView
    CGRect viewFrame = self.scrollView.frame;
    // I'm also subtracting a constant kTabBarHeight because my UIScrollView was offset by the UITabBar so really only the portion of the keyboard that is leftover pass the UITabBar is obscuring my UIScrollView.
    viewFrame.size.height -= (keyboardSize.height - kTabBarHeight);

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    // The kKeyboardAnimationDuration I am using is 0.3
    [UIView setAnimationDuration:kKeyboardAnimationDuration];
    [self.scrollView setFrame:viewFrame];
    [UIView commitAnimations];

    keyboardIsShown = YES;
}

iphone - problem while moving the screen upwards when we hit on the te...

iphone objective-c uitextfield
Rectangle 27 0

The easiest way is to subclass a UIView, have your UIViewController add an instance of the subclass as a visible sub view, and call setNeedsDisplay on it. Then, when the drawRect method of your UIView subclass gets called, do your quartz drawing on the context given.

objective c - How to draw on UIView - Stack Overflow

objective-c ios ios5
Rectangle 27 0

If your view is exhibiting behavior, it should be within a view controller. On a view controller, the viewDidAppear method will be called each time the view appears.

- (void)viewDidAppear:(BOOL)animated

The problem with viewDidAppear is, that it only get's called when using a Navigation-Controller. In my case, the views get scrolled off the screen, then get scrolled back. Scrolling seems not to trigger viewDidAppear....

So what can indicate if the view is appeared on screen with scroller?

iPhone: Howto get notified when an UIView becomes visible - Stack Over...

iphone uiview uiscrollview
Rectangle 27 0

A UIView is always a Rectangular shape, you can't alter that. However, you could perhaps get the effect you want by using CALayer masking. Make a UIView and apply a custom mask to it, whereby the mask has the appropriate data in it for a triangle. Then any actual content you put in your UIView will only be visible in the appropriate 'triangle' shaped area.

To make your mask layer, you can either use an Image (e.g. a png) or use Core Graphics to draw a triangle. There are certain things you can do :

iphone - Detecting touches on a part of UIImageView - Stack Overflow

iphone cocoa-touch uiimageview
Rectangle 27 0

You can load view from XIB file:

// I assume, that there is only one root view in interface file
NSString *nibName = @"CustomView";
NSArray *loadedObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil];
UIView *view = [loadedObjects lastObject];

Very nice! Thank you. Is the loaded view returned as auto-released?

iphone - How to get a UIView from a UIViewController without adding th...

iphone overlay xib nib
Rectangle 27 0

If your view is exhibiting behavior, it should be within a view controller. On a view controller, the viewDidAppear method will be called each time the view appears.

- (void)viewDidAppear:(BOOL)animated

The problem with viewDidAppear is, that it only get's called when using a Navigation-Controller. In my case, the views get scrolled off the screen, then get scrolled back. Scrolling seems not to trigger viewDidAppear....

So what can indicate if the view is appeared on screen with scroller?

" it should be within a view controller." - and view controllers only work with full screen views. Sometimes we have views that cover only a part of screen.

cocoa touch - How can I get notified when a UIView becomes visible? - ...

cocoa-touch uiview uiscrollview
Rectangle 27 0

I don't think there's a universal way to do this for views. Sounds like you're stuck with scrollViewDidEndScrolling and other ScrollViewDelegate methods. But I'm not sure why you say it's elegant, they're quite straightforward.

cocoa touch - How can I get notified when a UIView becomes visible? - ...

cocoa-touch uiview uiscrollview
Rectangle 27 0

There is no way to move the status bar; it is either visible or hidden. However, you can get around this by replacing the status when the UITableView is about to be scrolled with a UIView containing a screenshot that includes the status bar.

I would start with the UIScrollViewDelegate. Since the UITableViewDelegate is a subclass of the UIScrollViewDelegate, you can, in your view controller, set your UITableView's delegate to self. With this, you can now listen to scrolling movements.

When the UITableView is at the top and the user is scrolling down, I would recommend to take a screenshot of the status bar, add it to a UIView, and move that said view up at the same speed as the UITableView is moving (see the UIScrollViewDelegate documentation for help). Likewise, when scrolling to the top, I would have the view move down to the position of the status bar, then remove the view, and set the status bar visible.

With this method, you have the appearance of the status moving up and down with the table view.

ios - How to hide status bar gradually in swift - Stack Overflow

ios swift
Rectangle 27 0

UIViews are backed by CALayers, and it is the layer that does the actual animation. CALayer exposes a property presentationLayer which, when accessed, returns a copy of the CALayer that represents, as closely as it can, the current state visible to the user. By asking for the view.layer.presentationLayer.frame you can get the frame of the layer as visible to the user right now, and this corresponds to the frame of the UIView.

ios - UIView animation determine center during animation - Stack Overf...

ios animation uiview nstimer center
Rectangle 27 0

You can do this with a full height table view. Just add it in a UIView controller, and add the label to the view controller's view (not to the table view) also. Set paging enabled for your table, and set the row height to the height of the table view. You can get the row of the visible cell with this code, and do whatever you want with that number to update your label,

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSArray *paths = self.tableView.indexPathsForVisibleRows;
    NSInteger row = [paths[0] row];
    ContainerViewController *parent = (ContainerViewController *)self.parentViewController;
    parent.label.text = [NSString stringWithFormat:@"This is picture %d", row];
}

Thanks! The problem is that I have to use the PFQueryTableViewController subclass for UITableViewController to get data from Parse cloud, and I can't figure out how to acheive that when I embed UITableView inside UIViewController.

@maxster256, that makes it slightly more complicated, but still easily doable. You need to have an initial view controller to which you add a full sized container view. Embed the PFQueryTableViewController in that container view, and add the label to the container controller's view. In the PFQueryTableViewController, import the container view controller's class, and use the modified code in my answer.

ios - Label outside of UITableViewCell updating for the cell currently...

ios objective-c uitableview uilabel fixed
Rectangle 27 0

view's layer property should tell us if that view is visible or not

[view.layer visibleRect];

So work around could be to use UiScrollView contentOffset property to calculate if particular view is visible or not.

iPhone: Howto get notified when an UIView becomes visible - Stack Over...

iphone uiview uiscrollview
Rectangle 27 0

First, add a category for UIView with the following method:

// retrieve an array containing all super views

-(NSArray *)getAllSuperviews
{
    NSMutableArray *superviews = [[NSMutableArray alloc] init];

    if(self.superview == nil) return nil;

    [superviews addObject:self.superview];
    [superviews addObjectsFromArray:[self.superview getAllSuperviews]];

    return superviews;
}

Then, in your View, check if the window-property is set:

-(void)didMoveToWindow
{
    if(self.window != nil)
        [self observeSuperviewsOnOffsetChange];
    else
        [self removeAsSuperviewObserver];
}

If it is set, we'll observe the "contentOffset" of each superview on any change. If the window is nil, we'll stop observing. You can change the keyPath to any other property, maybe "frame" if there is no UIScrollView in your superviews:

-(void)observeSuperviewsOnOffsetChange
{
    NSArray *superviews = [self getAllSuperviews];
    for (UIView *superview in superviews)
    {
        if([superview respondsToSelector:@selector(contentOffset)])
            [superview addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
    }
}

-(void)removeAsSuperviewObserver
{
    NSArray *superviews = [self getAllSuperviews];
    for (UIView *superview in superviews)
    {
        @try
        {
            [superview removeObserver:self forKeyPath:@"contentOffset"];
        }
        @catch(id exception) { }
    }
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if([keyPath isEqualToString:@"contentOffset"])
    {
        [self checkIfFrameIsVisible];
    }
}

Finally, check if the view's frame is visible inside the window's frame:

-(void)checkIfFrameIsVisible
{
    CGRect myFrameToWindow = [self.window convertRect:self.frame fromView:self];
    if(myFrameToWindow.size.width == 0 || myFrameToWindow.size.height == 0) return;
    if(CGRectContainsRect(self.window.frame, myFrameToWindow))
    {
        // We are visible, do stuff now
    }
}

iPhone: Howto get notified when an UIView becomes visible - Stack Over...

iphone uiview uiscrollview
Rectangle 27 0

+ (id) getCurrentUIViewController : (id)res {
   if([res isKindOfClass:[UIViewController class]]) {
      return res;
   }
   else if ([res isKindOfClass:[UIView class]]) {
      return [Function getCurrentUIViewController:[res nextResponder]];
   }
   else {
      return nil;
   }
}

ios - Get size of currently visible UIViewController from a UIView - S...

ios objective-c iphone uiview uiviewcontroller
Rectangle 27 0

There is no way to move the status bar; it is either visible or hidden. However, you can get around this by replacing the status when the UITableView is about to be scrolled with a UIView containing a screenshot that includes the status bar.

I would start with the UIScrollViewDelegate. Since the UITableViewDelegate is a subclass of the UIScrollViewDelegate, you can, in your view controller, set your UITableView's delegate to self. With this, you can now listen to scrolling movements.

When the UITableView is at the top and the user is scrolling down, I would recommend to take a screenshot of the status bar, add it to a UIView, and move that said view up at the same speed as the UITableView is moving (see the UIScrollViewDelegate documentation for help). Likewise, when scrolling to the top, I would have the view move down to the position of the status bar, then remove the view, and set the status bar visible.

With this method, you have the appearance of the status moving up and down with the table view.

ios - How to hide status bar gradually in swift - Stack Overflow

ios swift
Rectangle 27 0

view's layer property should tell us if that view is visible or not

[view.layer visibleRect];

So work around could be to use UiScrollView contentOffset property to calculate if particular view is visible or not.

So how do you add a trigger that's fired when that value changes?

I answered this question long ago, even i forgot the context. Subclass UIView and use following methods. developer.apple.com/library/ios/documentation/UIKit/Reference/

that's what I'm doing now. I want to listen from an outside class.

cocoa touch - How can I get notified when a UIView becomes visible? - ...

cocoa-touch uiview uiscrollview