uiview interview questions
Top uiview frequently asked interview questions
My login view has a subview which has a UIActivityView
and a UILabel
saying "Signing In…". This subview has corners which aren't rounded. How can I make them round?
Is there any way to do it using a nib/xib?
Source: (StackOverflow)
UIView
and its subclasses all have the properties frame
and bounds
. What's the difference? (Please don't quote the Apple docs — I've already read them and did not understand.)
Source: (StackOverflow)
How do I add a touch event to a UIView?
I try:
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, nextY)] autorelease];
[headerView addTarget:self action:@selector(myEvent:) forControlEvents:UIControlEventTouchDown];
// ERROR MESSAGE: UIView may not respond to '-addTarget:action:forControlEvents:'
I don't want to create a subclass and overwrite
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Thanks!
Source: (StackOverflow)
I want to move one view on top of another, how can I know the z index of the view, and how to move on to top? Thank you.
Source: (StackOverflow)
I would like to know how to use these properties in the right manner.
As I understand, frame
can be used from the container of the view I am creating.
It sets the view position relative to the container view. It also sets the size of that view.
Also center
can be used from the container of the view I'm creating. This property changes the position of the view relative to its container.
Finally, bounds
is relative to the view itself. It changes the drawable area for the view.
Can you give more info about the relationship between frame
and bounds
? What about the clipsToBounds
and masksToBounds
properties?
Source: (StackOverflow)
UIView
has the properties frame
, bounds
, center
, and origin
, and they all seem to be interrelated. Most of the time, I deal with frame
when setting the position and size of a UIView
. I understand that frame
is using global coordinate system and bounds
is using coordinate of the local view (therefore its x and y are 0, but not always), but it's still confusing to me when to use what.
Under what context (and what's the right time) the other properties (bounds
, center
, origin
) should be used?
Source: (StackOverflow)
I had some confusions, which I think I have resolved them now, but just wanted confirmation.
I was in an (probably false) assumption that enabling the right margin indicator in xib is equivalent to using UIViewAutoresizingFlexibleLeftMargin
inside code and so on.
So, I used to think according to this snapshot:
Later today I had to cross check, and stumbled upon this thread.
And also the apple documentation, entitled with the section with title - "Handling Layout Changes Automatically Using Autoresizing Rules" in this link: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html
So I now have a renewed concept in my mind as to how setting autoresizing masks programmatically would be equivalent to xib settings:
Scenario 1:
Setting only (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)
is equivalent to:
In XIB?
Scenario 2:
Setting (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin)
in code is equivalent to:
In XIB?
Are my 2 renewed scenarios correct? Am I right now in my understanding?
Thanks,
Raj
Source: (StackOverflow)
I'm trying to rotate a UIImageView
360 degrees, and have looked at several tutorials online. I could get none of them working, without the UIView
either stopping, or jumping to a new position.
The latest thing I've tried is:
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
But if I use 2*pi, it doesn't move at all (since it's the same position). If I try to do just pi (180 degrees), it works, but if I call the method again, it rotates backwards.
EDIT:
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
[UIView setAnimationRepeatCount:HUGE_VALF];
[UIView setAnimationBeginsFromCurrentState:YES];
imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
doesn't work either. It goes to 180 degrees, pauses for a split second, then resets back to 0 degrees before it starts again.
Source: (StackOverflow)
I've literally tried everything I could but none of them work for a custom UIView
... I just wanted a blank white view with rounded corners and a light drop shadow (with no lighting effect). I can do each of those one by one but the usual clipToBounds
/maskToBounds
conflicts occur.
Source: (StackOverflow)
The position of a UIView
can obviously be determined by view.center
or view.frame
etc. but this only returns the position of the UIView
in relation to it's immediate superview.
I need to determine the position of the UIView
in the entire 320x480 co-ordinate system. For example, if the UIView
is in a UITableViewCell
it's position within the window could change dramatically irregardless of the superview.
Any ideas if and how this is possible?
Cheers :)
Source: (StackOverflow)
Is there a built-in way to get from a UIView
to its UIViewController
? I know you can get from UIViewController
to its UIView
via [self view]
but I was wondering if there is a reverse reference?
Source: (StackOverflow)
Is there a way to set cornerRadius for only top-left and top-right corner of a UIView?
EDIT:
I tried the following, but it end up not seeing the view anymore. Anything wrong with the code below?
UIView *view = [[UIView alloc] initWithFrame:frame];
CALayer *layer = [CALayer layer];
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(3.0, 3.0)];
layer.shadowPath = shadowPath.CGPath;
view.layer.mask = layer;
Source: (StackOverflow)
What is considered best practice for animating view transitions on the iPhone?
For example, the ViewTransitions
sample project from apple uses code like:
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:1];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myview layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
but there are also code snippets floating around the net that look like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myview cache:YES];
[myview removeFromSuperview];
[UIView commitAnimations];
What is the best approach? If you could provide a snippet as well it'd be much appreciated.
NOTE: I've been unable to get the second approach to work correctly.
Source: (StackOverflow)
I have always been a bit unclear on the type of tasks that should be assigned to viewDidLoad vs. viewWillAppear: in a UIViewController subclass. For example, I am doing an app where I have a UIViewController subclass hitting a server, getting data, feeding it to a view and then displaying that view. What are the pros and cons of doing this in viewDidLoad vs. viewWillAppear?
Thanks in advance.
Cheers,
Doug
Source: (StackOverflow)