cocoa: resize split view subview size - cocoa

I want to hide a subview after I click a button, for example.
after I click hide button, the application should hide the NSTabView,(Not NSTableView!!!). but the problem is the NSTableView at top didn't resize, as follow:
How to make NSTableView auto resize to fill the blank after I hide the NSTabView?
My code about hiding the bottom subView:
NSRect frame = [self.customView frame];
frame.size = NSMakeSize(0, 0);
[[self.customView animator] setFrame:frame];

In your code for the hide button, just include code that increases the frame size of your scroll view (that contains the table view).

Related

NSView layer shadow draws on subviews, not view itself

I'm trying to set a shadow on the layer of an NSView, but the layer is being drawn on the subviews of my view, not the view itself. What can be causing this?
The view in question and all its subviews are layer-backed. All but one of the subviews are buttons (NSButton) with images - the other one is a custom view that renders via drawRect:.
self.layer.shadowColor = [[NSColor blackColor] colorWithAlphaComponent:0.9].CGColor;
self.layer.shadowRadius = 2;
self.layer.shadowOffset = NSMakeSize(0, -1);
self.layer.shadowOpacity = 0.9;
I've also tried setting the shadow via an NSShadow, with the same outcome.
Turns out that if you set a shadow on an NSView's layer, it only draws on that view if the view has a drawRect: implementation that draws something non-transparent. Otherwise it draws on all the view's subviews.
Weird.

UiScrollview with nested image looks weird

I have a UIScrollView inside a UIViewController (subclassed by ImageViewController). The ViewController itself is part of a NavigationController's stack. Now, apart from having a navigation bar, I want the ScrollView to take all of the available room on the screen. The UIImageView inside the scrollview should then fill the available room of the scroll view. You can see the current state at the bottom of this posting.
class ImageViewController: UIViewController, UIScrollViewDelegate {
#IBOutlet weak var scrollView: UIScrollView!
var imageView: UIImageView?
var image: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
if let image = image {
imageView = UIImageView(image: image)
if let imageView = imageView {
imageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: image.size)
scrollView.addSubview(imageView)
scrollView.contentSize = image.size
let scaleHeight = scrollView.frame.size.height / scrollView.contentSize.height
let scaleWidth = scrollView.frame.size.width / scrollView.contentSize.width
let minimumScale:CGFloat = min(scaleHeight, scaleWidth)
let maximumScale:CGFloat = max(scaleHeight, scaleWidth)
scrollView.minimumZoomScale = minimumScale
scrollView.maximumZoomScale = maximumScale
scrollView.zoomScale = maximumScale
}
}
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return imageView
}
}
The code leaves me with unnecessary borders (left, right, top). How do I get rid of them?
EDIT: With #Bxtr's suggestion and another stackoverflow thread I was able to remove the borders left and right to the scroll view. After some more digging I found out that by deactivating Adjust Scroll View Insets, the image inside the scroll view can be correctly vertically positioned. Still, I do not get the reason for the vertical misplacement in the first place...
Have you checked the margin/padding values, because it kinda looks so (same size on left and right border). If it is not the case, could you please also post your xml file of the activity so we can have every part of the puzzle to help you ?
scrollView.contentSize = image.size;
you have to tweek this line. You are explicitly setting scroll view content size to the image size. You have to set content size to fit the Width of Screen.
You can use a UIView in UIScrollView, and that UIView contains UIImage.
You need to set constraints properly.
After some more digging I found out that by deactivating Adjust Scroll
View Insets, the image inside the scroll view can be correctly
vertically positioned. Still, I do not get the reason for the vertical
misplacement in the first place...
The reason is that the view controller's automaticallyAdjustsScrollViewInsets property is by default YES, the following is from apple documentation:
automaticallyAdjustsScrollViewInsets
A Boolean value that indicates
whether the view controller should automatically adjust its scroll
view insets.
Default value is YES, which allows the view controller to adjust its
scroll view insets in response to the screen areas consumed by the
status bar, navigation bar, and toolbar or tab bar. Set to NO if you
want to manage scroll view inset adjustments yourself, such as when
there is more than one scroll view in the view hierarchy.
Besides setting automaticallyAdjustsScrollViewInsets = No, you can pin the scrollView to the topLayoutGuide (instead of to the top of the viewController's view) when using autoLayout.

UIScrollView not scrolling horizontally despite setting contentSize

I have a simple app with multiple UITableViews, all of whom redirect to a single ViewController, with 2 items: a Label, and an ImageView embedded into a scrollview.
The problem is, the image, even though resized to exceed the screen size, does not scroll horizontally. It only scrolls vertically.
GammaViewController.h :
IBOutlet UIScrollView *testScroll;
GammaViewController.m :
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = #"Gamma View";
finalLabel.text= _selectedData;
[testScroll setScrollEnabled:YES];
[testScroll setContentSize:CGSizeMake(600,800)];
}
The ImageView has been assigned an image from the Attributes inspector, and has been resized to the scrollview contentSize i.e. (600,800).
May be a silly mistake that content size and frame may be same.
Try this
[testScroll setFrame:CGRectMake(0,0,320,400)];
[testScroll setContentSize:CGSizeMake(600,800)];
May this code help you.

Resizing tableview height programmatically

I am using storyboard in xcode 4.5.
In my application there is 2 views, view1 and view2.
Each view has a tableview.
A navigation controller is connected to the views.
I am trying to change the height of the tableview depending on the size of the Iphone display.
I am using the following code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Verify if the screen is iphone 5
if ([[UIScreen mainScreen] bounds].size.height == 568){
// Resize table hight
CGRect tvframe = [_myTableView frame];
[_myTableView setFrame:CGRectMake(tvframe.origin.x,
tvframe.origin.y,
tvframe.size.width,
tvframe.size.height + 64)];
}
The problem is that the code has no effect when the application starts and view1 appears.
But when I move to view2 and then back to view1 the resizing takes effect.
I don't understand why the reszing doesn't take effect when the application starts.
Have you tried moving the code to ViewWillAppear? That should fix the problem.

how to do animated transition between different UIViewControllers within a UITabBarController?

I have a UITabBarController,displaying 4 tabs.
I want to add an animated UIViewController transition when user swiping screen to switch tab. (- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController method only work for select tab directly). transition will be in easeinout style.
I tried following codes but not work. only coming UIViewController moves, going UIViewController doesn't show at all.(I printed all UIViewControllers' frame data, all these 4 UIViewControllers are {0,0},{320,480} )
// Get views. controllerIndex is passed.
UIViewController *fromVC = [_tabBarController.viewControllers objectAtIndex:startIndex];
UIViewController *toVC = [_tabBarController.viewControllers objectAtIndex:to];
UIView *fromView = fromVC.view;
UIView *toView = toVC.view;
MWLog(#"from view is %#",fromView);
int direct = startIndex - to;
// calculate move direction.
if (direct < 0) {
CGRect outFrame = fromView.frame;
outFrame.origin.x = -320; // expect fromView will move to {-320,0}, out of screen.
MWLog(#"fromView's frame is %#", NSStringFromCGRect(fromView.frame));
CGRect inFrame = toView.frame;
inFrame.origin.x = 0;
MWLog(#"toView's frame is %#", NSStringFromCGRect(toView.frame));
[UIView beginAnimations:#"moveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5f];
toView.frame = inFrame;
fromView.frame = outFrame;
[UIView commitAnimations];
}else
{
// reverse moving. ignored....
}
Could you tell me what's wrong and how to do it correctly? thanks in advance!
finally I found the solution.
use CATransition animation, type push, type left or right depending on direction(by calculating tabbarcontroller's selectedIndex property). then, add this animation to tabbarcontroller's container view.
This view's reference can be got by enumerate all UIViews in [tabbarcontroller subviews] array. Actually, if no custom UIView, tabbarcontroller contains 2 subviews, one is UITabBar, the other is the container view, UITransitionView. Add animation on this view, you can enable page transition animation for different content screen.

Resources