Rectangle 27 19

Since the playerLayer is being added as a sublayer and not as a subview it simply needs to be removed from its superlayer (instead of the superview) and the player should be set to nil, something like:

/* not sure if the pause/remove order would matter */
[playerLayer.player pause];
// uncomment if the player not needed anymore
// playerLayer.player = nil;
[playerLayer removeFromSuperlayer];

Excuse me, sorry it's been a long time. But, where should I put the code below? in viewDidDisappear: or viewWillDisappear: ? I tried both, but none of them worked.... could you please help me? Thanks in advance.

iphone - Can't remove or stop AVPlayer - Stack Overflow

iphone ios ios5 avplayer
Rectangle 27 200

If my superview is a box measuring 10 units on each side, and my subview is 20 units wide, with clipsToBounds set to YES, I'll only see the part of the subview that fits within the bounds of the superview. Otherwise, if clipsToBounds is set to NO, I'll see the entire subview, even the parts outside the superview (assuming we're still on the screen).

As a visual example, consider the following views set up on the storyboard:

This is a white UIView, a label in the top left corner with either a simple "1" or "2" so that I can discuss these as view1 or view2. Additionally, the black view is the same size as the white view, but it's origin is at the white view's center.

In the view controller's viewDidLoad method, we have the following code:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view1.clipsToBounds = YES;
    self.view2.clipsToBounds = NO;
}
override func viewDidLoad() {
    super.viewDidLoad()
    self.view1.clipsToBounds = true
    self.view2.clipsToBounds = false
}

When we run the code and look at in the simulator or on the device, we get the following results:

So, despite these views being set up identically (except clipsToBounds), they look different. This is what clipsToBounds does. Setting it to YES will provide the top result, while setting it to NO provides the bottom result.

If we debug the view hierarchy, we can see more clearly that the black boxes both do actually extend past the boarders of the white view, but only view 2 shows this when the app is actually running:

Fantastic answer! Well done. But I have a question. Why UITextView shadows are not visible, if the clipsToBounds property equal to the true; ? If it's false, works just fine

ios - How does clipsToBounds work? - Stack Overflow

ios uiview uikit frame bounds
Rectangle 27 17

UITabBarController expects to have its view added as a subview of UIWindow, not as a subview of some other UIView. The frame property defines the offset of the view within its superview, so the UITabBarController implementation offsets its view's frame by 20 pixels by default to leave room for the status bar. You're using UITabBarController in a nonstandard way by adding it to a view that's already been offset by 20 pixels for the status bar. UITabBarController offsets its view by an additional 20 pixels relative to its superview, causing the gap you see.

One clean way to fix this is add the UITabBarController's view as a subview of the window instead of a view:

[[[UIApplication sharedApplication] keyWindow] addSubview:tabbarController.view];

(Note: The keyWindow method will only return your window if you've already called makeKeyAndVisible. Otherwise, you may want to set a window property on your UIViewController.)

Thanks for clear explanation. Maybe I should go back and restructure part of my app. I want to do things the correct way, but I thought it may be better to separate the view controller logic from the app delegate - so my root view controller does all that it needs. That would explain why in my root view controller if I did self.view = tabbarController.view instead of adding as a subview, I wouldn't get the gap. Great answer. I'd vote up more if I could.

It sounds like your instinct was good here. This is just one of those design limitations in Cocoa Touch that we have to work around for now. Bear in mind though that you don't necessarily need add the tabbarController.view to your window from your app delegate. You can add it in your view controller if that's where you think it makes the most sense. You just need to have access to the window object, either via the keyWindow method, or by setting it as a property on your controller back in applicationDidFinishLaunching:.

but doesn't this mean that the tabbarcontroller.view is now a subview of the window.view? But it's not correct in my case i have an ad view, and then a second contentview. And I'm adding the tabbarcontroller.view to the contentview. In this fashion the viewcontroller will handle the content/adview depending on ads. if i add the tabbarcontroller.view to the window, i don't think i'll be able to handle the views using my viewcontroller. what do you think?

The UITabBarController Class Reference says, "When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller." I understand why you want tabbarcontroller.view to be a subview of a different view in your case. Unfortunately you'd have to fight against the fact that this class adjusts its frames based on the assumption that its view is a subview of the window. Consider using UITabBar in a custom UIViewController that implements UITabBarDelegate.

Interesting, how would I add 20px to a viewcontroller tab (child) of the UITabBarController to offset for the iOS7 status bar? Ive tried many SO solutions and none work. stackoverflow.com/questions/18921062/

uikit - IPhone - UIView addSubview Gap at top - Stack Overflow

iphone uikit uiview
Rectangle 27 2

I solved my problem in the following way. When the subview of the scrollview receives a touchesBegan:withEvent: I set the alpha of that subview to 0.0. I then create an identical subview and add it to the scrollview's superview. For the initial position I use the following:

CGPoint newOrigin = [self origin];
newOrigin.x = newOrigin.x + [[self superview] origin].x;
newOrigin.y = newOrigin.y + [[self superview] origin].y - [(UIScrollView*)[self superview] contentOffset].y;
[newSubview setOrigin: newOrigin];  // setOrigin is defined in a category on UIView - it does what you'd expect

(Note - if you don't compensate for the scrollview content offset you can get puzzling behaviour...)

My touchesMoved:withEvent method moves the subview (as per normal for implementing dragging) and then touchesEnded:withEvent removes the extra subview from the scrollview's superview and sets the alpha of the initial subview back to 1.0. So, in effect, the additional subview, piggy backs on the invisible subview.

iphone - How to implement a "selective" clipToBounds for a UIView, i.e...

iphone uiview subview
Rectangle 27 8

Clipstobounds : withclipsToBoundsset toYES, I'll only see the part of the subview that fits within the bounds of the superview. Otherwise, ifclipsToBoundsis set toNO, I'll see the entire subview, even the parts outside the superview

Maskstobounds: If themasksToBoundsproperty is set to YES, any sublayers of the layer that extend outside its boundaries will be clipped to those boundaries. Think of the layer, in that case, as a window onto its sublayers; anything outside the edges of the window will not be visible. WhenmasksToBoundsis NO, no clipping occurs, and any sublayers that extend outside the layer's boundaries will be visible in their entirety (as long as they don't go outside the edges of any superlayer that does have masking enabled).

can you please attach screenshot of that for more understanding..

Sorry Bro ...I couldn't ,don't have much reputations otherwise I could provide a nice example through screen shot

ios - Maskstobounds vs clipstobounds - Stack Overflow

ios objective-c swift cocoa-touch
Rectangle 27 5

Frame is in the superview's coordinate system, bounds is in the view's coordinate system. From my perspective, it is a convenience to have both. Frame seems to be the more useful of the two, unless there is some case I am unaware of where a subview can have a completely different coordinate system (e.g. pixels scaled differently) than the superview.

There is. If you change the subview's transform property, for example by setting its rotation, its bounds will be unchanged, but its coordinate system will be different than that of the superview.

iphone - Why is there an frame rectangle and an bounds rectangle in an...

iphone
Rectangle 27 3

You should know a UIView can have a single superview/parent. If you add it as a subview at a different position (using addSubview method) it will be removed from the first position and added as a subview to the new position. In your case to add more subviews you have to create more UIView objects not use a single global UIView. If the layout is repetitive a UITableView / UICollectionView is a better choice.

thanks guys for the answers, but I want to create a collection view without using storyboards. My entire project uses .xib files. I was not able to find any tutorial which showed creating collection views without storyboards. Can you share some links here?

It is pretty late I guess, but for other people who have not come across this yet, you can make a collection view or pretty much any other view programmatically. For a collection view, you just declare the view programmatically just like what you have up there for a uiview , just keep in mind you need to declare the layout programmatically as well in case you are using flow layout.

ios - How can I add same uiview multiples times at different positions...

ios swift uiview uiviewcontroller
Rectangle 27 1

Create a view in IB or code. Add your picker as a subview of this view. Resize the view. This is easiest to do in IB. Create constraints from the view to its superview and from the picker to this new view.

Since the Picker curves around it spills out over the top and bottom of the view. You can see in IB when you add top and bottom constraints from the picker to the view it shows a standard space something like 16 points above and below the superview container. Set the view to clip it if you don't want this behaviour (ugly warning).

Here's what it looks like at 96 points high on an iPhone 5. The picker with the spillover is about 130 points high. Pretty skinny!

I'm using this in my project to prevent the picker from spreading out to an unnecessary height. This technique trims it down and forces a tighter spill over. It actually looks slicker to be a bit more compact.

Here's an image of the view showing the spillover.

iphone - How to change UIPickerView height - Stack Overflow

iphone cocoa-touch uikit uipickerview
Rectangle 27 1

I ended up adding a flag property on my superview and then set it to YES from my subview to prevent it from laying out subviews. Seems very hacky but it works.

ios - iPhone - layoutSubviews being called when updating subview - Sta...

ios uikit layoutsubviews
Rectangle 27 4

The issue in your code is, when you call removeFromSuperview the view will be released by the parent view. No need of calling removeFromSuperview, just add it as subview of another view will remove it from it's current parentView.

for (UIView *view in self.view.subviews)
{
    if (view.tag != 666)
    {
        [self.contentView addSubview:view];
    }
}

Adds a view to the end of the receivers list of subviews.

- (void)addSubview:(UIView *)view
The view to be added. This view is retained by the receiver. After being added, this view appears on top of any other subviews.

This method retains view and sets its next responder to the receiver, which is its new superview.

Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview

ios - Remove a view from one view and add it to another - Stack Overfl...

ios objective-c uiview addsubview
Rectangle 27 1

Yes, it is true that in your case the subview will be retained by the view, so we don't technically need to retain it again. However, that is kind of fragile. What if in the future you add some code that removes that subview from its superview? Then you have a dangling pointer unless you make sure to nil it out.

It is general convention to retain instance variables, unless it is necessary not to (e.g. for delegates). If we go down the path of saying "oh we don't need to retain this instance variable because it's retained here; oh we do need to retain this other one because it's not retained; etc.", then we end up with very haphazard memory management, where every time we add an instance variable, we have to go and think about whether it is retained by something else or not; and then every time we use it, we have to remember whether we decided to retain it or not. It is precisely the kind of memory management nightmare that the memory management rules are designed to avoid.

And retaining the instance variable, what harm does it do? In this case, it just causes an additional retain and release when we assign it. Not a big deal, for the benefit of simplicity and consistency.

"think about whether it is retained by something else or not" I would humbly argue that this is exactly what we should be thinking about. In fact the Apple documentation pointed to in a link above explicitly recommends to keep weak references to IBOutlets that are not at the top level of the object retain hierarchy.

ios - Why set retain on @property for subviews? - Stack Overflow

ios cocoa properties retain assign
Rectangle 27 1

Yes, it is true that in your case the subview will be retained by the view, so we don't technically need to retain it again. However, that is kind of fragile. What if in the future you add some code that removes that subview from its superview? Then you have a dangling pointer unless you make sure to nil it out.

It is general convention to retain instance variables, unless it is necessary not to (e.g. for delegates). If we go down the path of saying "oh we don't need to retain this instance variable because it's retained here; oh we do need to retain this other one because it's not retained; etc.", then we end up with very haphazard memory management, where every time we add an instance variable, we have to go and think about whether it is retained by something else or not; and then every time we use it, we have to remember whether we decided to retain it or not. It is precisely the kind of memory management nightmare that the memory management rules are designed to avoid.

And retaining the instance variable, what harm does it do? In this case, it just causes an additional retain and release when we assign it. Not a big deal, for the benefit of simplicity and consistency.

"think about whether it is retained by something else or not" I would humbly argue that this is exactly what we should be thinking about. In fact the Apple documentation pointed to in a link above explicitly recommends to keep weak references to IBOutlets that are not at the top level of the object retain hierarchy.

ios - Why set retain on @property for subviews? - Stack Overflow

ios cocoa properties retain assign
Rectangle 27 4

In addition to providing its own content, a view can act as a container for other views. When one view contains another, a parent-child relationship is created between the two views. The child view in the relationship is known as the subview and the parent view is known as the superview. The creation of this type of relationship has implications for both the visual appearance of your application and the applications behavior.

So when you set dimView.alpha = 0.4;(which is your super view) it automatically changes the opacity of it's sub views too. Because your super view holds those sub views and underlying layers which drawn by Core Animation.

If you want to change opacity of your super view only, you can do this via:

[dimView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.5]];

ios - Why do all the subviews of a UIView show translucency when the U...

ios objective-c uiview transparency
Rectangle 27 29

I think the concept you are missing is that a view's frame (and its center) are both in relation to its superview. Based on your screenshot I would guess that your textfields and buttons are all in a view that is acting as a container. So your button's frame & center are in relation to that container view and not to the view controller's view as a whole. You assign the same frame & center to the activity indicator, but then you add the indicator as a subview of the main view and not the container view. So you now have two views (the button and the indicator) with the same frame, but that frame is in relation to two different superviews.

The easiest change would just be to add your indicator to the container view you are using. But I would suggest adding the indicator as a subview of the button, then just do a little math to tweak its position.

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
CGFloat halfButtonHeight = btnLogin.bounds.size.height / 2;
CGFloat buttonWidth = btnLogin.bounds.size.width;
indicator.center = CGPointMake(buttonWidth - halfButtonHeight , halfButtonHeight);
[btnLogin addSubview:indicator];
[indicator startAnimating];

As a side note: Your setting of the center of a view just after the frame of the view is redundant. Also, the last view added as a subview is automatically the front subview.

ios - Place a UIActivityIndicator inside a UIButton - Stack Overflow

ios uiactivityindicatorview
Rectangle 27 2

When adding constraints to view that involves two views, the one view has to be a subview of the other, so you would need to add imageFromLink as a subview of darkOverLayView before you add the constraints. However, in this case, where you're adding a width and height constraint, those constraints should be added to imageFromLink, not to its superview. This type of fixed width or height constraint doesn't involve any other views, so it should belong to the view itself, not the superview.

Adding a height and width constraint doesn't center it in its superview however. You need to add (after making imageFromLink a subview) a centerX and centerY constraint to darkOverlayView as well.

ios - Why am I unable to set Auto Layout constraints when adding const...

ios objective-c uiimageview autolayout nslayoutconstraint
Rectangle 27 1

Sublayer (or Subviews) are always drawn 'above' their super layer (or Superview). Of course, because the superview acts as the container for the subview. You won't be able to change that behavior by zPosition or [insertSublayer:atIndex:]

The only thing you can do to hide the sublayer is by setting it's opacity value to 0 ..

I'm not 100% sure what you're trying to achieve .. maybe you could give us a bit more context ?

objective c - CALayer sublayer hides the parent layer - Stack Overflow

objective-c cocoa-touch calayer
Rectangle 27 3

It looks to me like when you call dismissFullScreenImage you are only removing the UIImageView from the superview. The blurEffectView is a separate subview entirely. You'll have to set a property for the effect view and then remove it when you call for the image to be removed. At the top of your class say something like like:

var blurEffectView:UIVisualEffectView!
didTapImageView
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.frame
dismissFullScreenImage
func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
    sender.view?.removeFromSuperview()
    blurEffectView.removeFromSuperview()
}

I don't know what you mean "how do I make it fullscreen?" .. The visual effect already is fullscreen. At least it looks that way on your screenshot.

by full screen I mean on top of everything. The way it is right now I can still scroll down on the table view, and I can see the navBar and tab bar

@BrunoRecillias - so you mean like you want it constantly pinned to the edges of the screen, even when you're scrolling?

like when you tap on an image on twitter or Facebook, it got full screen and you either tap/scroll down to dismiss the image. In my case I did a tap, but the image is not going full screen. I don't know if that makes sense

@BrunoRecillas - I think what you want to do is make an entire ViewController that just displays the image, and then when you tap on it, it dismisses and goes back to the main screen?

so there's no way of just putting the current blur on top of everything?

ios - Blur behind UIImage not going away after image is dismissed - St...

ios swift uiimageview uiimage swift3
Rectangle 27 2

From my understanding of your Views stack in your viewController, you simply need to move the transparent view to the front of the stack (it is currently at the back of your superView).

You can do this by calling.

And in the storyboard just set the view to the correct values

If you want to hide the view just call

[self.view bringSubViewToFront:<your tableView>];

To create a transparent view on top of you UITableView, you need to add a UIView in the storyBoard that is a subView of your viewController main view(then set all the attributes you want in the attributes inspector). Your tableView need to be also a subView of your viewController main view.

*make sure that the transparent view is front of the tableView in your storyBoard

In order to handle the gestures (because the transparent view is "blocking" the gestures from the tableView read this post Link)

tried it but not working

if I add [self.view bringSubViewToFront:<your transparent view>];then cellForRowAtIndexPath not getting called

can you add your code? from what you described it's not logical to happen

when do you want your transparent view to be on top? from the beginning?

ios - display list of images in UITableview with trasparent view - Sta...

ios objective-c iphone uitableview uiview
Rectangle 27 1

The frame rectangle gives the view's size and position in the superview. The frame is at position 0,0 (x,y) with a size of 0,0 (w,h) by default. The position in the subview collection is entirely ignored except in rare cases like NSSplitView.

objective c - In Cocoa View Hierarchy what determines the subView posi...

objective-c osx cocoa
Rectangle 27 1

Slightly easier and more straight forward than method than Fyodor Volchyok's answer. -Hold down the control button and click on the subview. -Still holding down on the command button, drag cursor to the superview then click on the superview. -Select "Aspect Ratio".

-Then click the Size Inspector. -Then double click on the constraint.

-Make sure that "height" is selected for both items.

-Then change the "Multiplier" to 0.5 for half the screen, or whatever fraction of the superview you desire.

ios - autolayout - make height of view relative to half superview heig...

ios autolayout