DevJuice

Latest

  • Dev Juice: Help me create a hidden logo

    by 
    Erica Sadun
    Erica Sadun
    07.06.2011

    Dear Dev Juice, How do you implement that slightly egotistical Apple logo hidden in iBooks.app if you drag the bookshelf down from the top? Brandon E. Dear Brandon Ah. You speak of the hidden drag-to-reveal logo. Actually, that's super-easy to do. Just remember that you can add subviews to scroll views and place them in that magic elastic zone at the top. Take tables for example. Lots of devs now add "pull-to-refresh" feature to the top, similar to Apple's logo. As with the scrollview, make sure to set the origin above the normal start, i.e. use negative numbers of at least the size of whatever view you add. Here's the basic approach. Adapt it as needed. // Add the "Pull to Refresh" above the table. // Ensure bounces and alwaysBounceVertical are enabled. UIView *pullView = [[[NSBundle mainBundle] loadNibNamed:@"HiddenHeaderView" owner:self options:nil] lastObject]; pullView.frame = CGRectOffset(pullView.frame, 0.0f, -pullView.frame.size.height); [self.tableView addSubview:pullView]; Happy developing!

  • Dev Juice: How do I autocomplete in Xcode 4?

    by 
    Erica Sadun
    Erica Sadun
    07.05.2011

    Dear Dev Juice, I just moved from Xcode 3 to Xcode 4. How can I make autocomplete give me a template? I type -(void)deal and the drop down pops up. tab just completes the dealloc word. I want it to pop out the template for me. Space bar doesn't work, enter, escape, nothing anymore. I need to know how to make it dump the template Tigerpaw Dear Tigerpaw, Xcode 4 offers a slightly different take on text macros. Code snippets are now the way to go. The problem is that you're typing -(void) deal and expecting it to expand to the skeletal dealloc method. What you need to do is this. Go outside of any method and type de. No "- (void)". Immediately, Xcode will pop-up a completion menu and the first choice will be dealloc. That's because you need use code snippets by name in Xcode 4, not by structure. You can find out the name of your snippet by using the Code Snippet Library browser. Enter dea in the text field at the bottom of the browser. It returns just one match, "Objective-C dealloc Method". Hover over the selected item until a pop-up appears and then click Edit. Here you'll find the completion shortcut name. As you can see, the name here is "dealloc". Creating your own custom snippets and naming them with shortcuts is just as easy. Select text in the Xcode code editor. Click and hold for a second in the selection and then drag it over to the library. It appears at the end of the library list and is named My Code Snippet by default. Do the hover/pop-up/edit trick again to enter the edit mode above. Change the snippet's title, summary, and completion shortcut and click Done. Your new snippet will now be available for use using the shortcut you assigned. Enter the first few characters, press return. Presto. Should you want to add a placeholder into your new snippet, surround it with <# and #>, e.g. int foo = <#value#>; Xcode automagically converts this into a placeholder in the editor.

  • Dev Juice: Help me fix my UIView animations

    by 
    Erica Sadun
    Erica Sadun
    06.21.2011

    Dear Dev Juice, I'm having an issue with UIView animations, that I'm struggling to describe in keywords, so I can't find anything helpful with Google. The problem is that I can't seem to work out how to make a UIButton move relative to the bottom of the parent view, as I shrink the parent view. I've managed to get the other views inside the parent to scale with an autoresize mask, but I cannot for the life of me work out how to make the bottom (or even center) of my button clip on to the bounds of the view. Not sure if that accurately paints the picture, and I'm not sure if it's relevant, but I'm making a widget for NotificationCenter. Hope you can help, I'm tearing my hair out. Thanks, Rory W. Dear Rory, It's still the autoresizing mask you have to deal with, but you need to be working with the struts instead of the springs. The Autosizing pane in Interface Builder lets you establish a fixed distance between a view and its parent's edge. Imagine setting a view at 40 points from the top and left of the superview. Enabling the top and left struts in the inspector fixes that view at its relative position. When you use a right or bottom strut, those distances are also maintained. The view must either move or resize to stay the same distances from those sides. The equivalents of struts in code are UIViewAutoresizingFlexibleLeftMargin, UIViewAutoresizingFlexibleRightMargin, UIViewAutoresizingFlexibleTopMargin, and UIViewAutoresizingFlexibleBottomMargin. These flags allow a view to resize by expanding or shrinking in the direction of a given margin without affecting the size of any items inside. Although each of these correspond to the struts of Interface Builder's Autosizing pane, they act in the opposite way. In IB, struts fix the margins; the flags allow flexible resizing along those margins. Enjoy your afternoon sip of Dev Juice!