Core Graphics Tutorial: Glossy Buttons

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

Core Graphics Tutorial: Glossy Buttons

Postby rwenderlich » Thu Apr 18, 2013 11:00 am

This is the official thread to discuss the following blog post: Core Graphics Tutorial: Glossy Buttons
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2237
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 372 times

Re: Core Graphics Tutorial: Glossy Buttons

Postby tomneo2004 » Fri Apr 19, 2013 6:23 am

Great tutorial.

"enter the name CoolButton as the class name. In the subclass field, type UIView."
Should UIView be changed to UIButton?
tomneo2004
Hacker
 
Posts: 29
Joined: Wed Jun 13, 2012 6:43 am
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Glossy Buttons

Postby rwenderlich » Fri Apr 19, 2013 3:04 pm

Good catch, fixed!
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2237
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 372 times

Re: Core Graphics Tutorial: Glossy Buttons

Postby algashev » Sun May 12, 2013 10:43 am

Highlighting the Button

To indicate when the button is pressed or not use this method:

Code: Select all
- (void)setHighlighted:(BOOL)highlighted
{
   [self setNeedsDisplay];
   [super setHighlighted:highlighted];
}
algashev
Baby Hacker
 
Posts: 9
Joined: Sun May 12, 2013 10:28 am
Has thanked: 0 time
Been thanked: 0 time

Postby Hokuang » Wed Jul 03, 2013 3:08 am

The highlighting code has a problem. When you put a button in a UITableViewCell, touch it and push in another view controller, then pop it. If you do this quickly, the button will keep highlighted. While using algashev's code seems correct.
Hokuang
n00b
 
Posts: 1
Joined: Wed Jul 03, 2013 2:58 am
Has thanked: 0 time
Been thanked: 0 time

Postby epinaud » Mon Sep 15, 2014 7:03 pm

Any chance somebody updates this tutorial series to Swift?

Regards,

Enrique.
epinaud
n00b
 
Posts: 2
Joined: Tue Jun 03, 2014 4:33 pm
Has thanked: 0 time
Been thanked: 0 time

Swift conversion problem

Postby GatoLoco » Wed Oct 01, 2014 9:39 pm

I altered the appearance of the glossy buttons to simulate buttons which depress below the plane of the keyboard. (Yes indeed, skeuomorphism!) An image of the result with the 5 key highlighted (i.e. depressed) is attached below. This alteration was done using the original Objective-C code from the tutorial.

I then converted the Objective-C code to Swift. However there were two (identical) lines for which I could not find the proper translation. They were the final lines in the touchesCancelled and touchesEnded functions which invoke the performSelector method. Their apparent purpose is to trigger a second invocation of the hesitateUpdate function after a delay. (Their purpose was never explained in the tutorial but probably has something to do with not leaving a button in a highlighted state under certain conditions.) Here is one of the functions:

Code: Select all
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesCancelled:touches withEvent:event];
    [self setNeedsDisplay];
    [self performSelector:@selector(hesitateUpdate) withObject:nil afterDelay:0.1];
}

My questions are:

(1) What was the purpose of the performSelector calls?

(2) What is the proper translation to Swift?

Thanks for a great tutorial Ray!
Attachments
Buttons.jpg
Buttons.jpg (5.72 KiB) Viewed 241 times
GatoLoco
Subscriber since Sep 19, 2014
Hacker
 
Posts: 17
Joined: Thu Dec 22, 2011 9:51 pm
Has thanked: 3 times
Been thanked: 0 time

Second Swift conversion problem

Postby GatoLoco » Wed Oct 01, 2014 10:13 pm

In addition to my previous post about converting the performSelector call to Swift I have another problem.

When I run the (Swift converted) glossy button app I get a SIGABRT when the first button is pressed. Here is the contents of the debug window. (Is it alright to post this much info in a forum?)
2014-10-01 14:58:29.864 ProButtons[16777:5181329] -[UIEvent _firstTouchForView:]: unrecognized selector sent to instance 0x7fc012c29740
2014-10-01 14:58:29.866 ProButtons[16777:5181329] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIEvent _firstTouchForView:]: unrecognized selector sent to instance 0x7fc012c29740'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e9c63f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110737bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010e9cd50d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010e9257fc ___forwarding___ + 988
4 CoreFoundation 0x000000010e925398 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010f599abf -[UIControl touchesBegan:withEvent:] + 64
6 ProButtons 0x000000010e7dff4a _TFC10ProButtons9PadButton12touchesBeganfS0_FTCSo5NSSet9withEventCSo7UIEvent_T_ + 138
7 ProButtons 0x000000010e7e000f _TToFC10ProButtons9PadButton12touchesBeganfS0_FTCSo5NSSet9withEventCSo7UIEvent_T_ + 95
8 UIKit 0x000000010f4da21e -[UIWindow _sendTouchesForEvent:] + 325
9 UIKit 0x000000010f4dace3 -[UIWindow sendEvent:] + 683
10 UIKit 0x000000010f4a7ae1 -[UIApplication sendEvent:] + 246
11 UIKit 0x000000010f4b4bad _UIApplicationHandleEventFromQueueEvent + 17370
12 UIKit 0x000000010f490233 _UIApplicationHandleEventQueue + 1961
13 CoreFoundation 0x000000010e8fbad1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010e8f199d __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010e8f0fd4 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010e8f0a06 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x00000001139ea9f0 GSEventRunModal + 161
18 UIKit 0x000000010f493550 UIApplicationMain + 1282
19 ProButtons 0x000000010e7e213e top_level_code + 78
20 ProButtons 0x000000010e7e217a main + 42
21 libdyld.dylib 0x0000000110f11145 start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I can see that the button's touchesBegan was called at which point something went terribly wrong. (The two functions touchesCancelled and touchesEnded containing the messing performSelector calls mentioned in my previous post have not yet been called so that is probably not part of this problem.)

I'm pretty new to all this and am at a loss to know where to begin looking. Can anyone suggest how to proceed?

Thanks.
GatoLoco
Subscriber since Sep 19, 2014
Hacker
 
Posts: 17
Joined: Thu Dec 22, 2011 9:51 pm
Has thanked: 3 times
Been thanked: 0 time


Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 13 guests