Facebook pop kPOPLayerCornerRadius is not working - ios

I have outlet from storyboard and pop animation code inside of IBaction (UIButton) :
#property (strong, nonatomic) IBOutlet UIView *animationView;
...
...
POPBasicAnimation *animationCircle = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerCornerRadius];
animationCircle.toValue = #(self.animationView.layer.cornerRadius/2);
animationCircle.name = #"animacijaCircle";
animationCircle.delegate = self;
[self.animationView pop_addAnimation:animationCircle forKey:#"animacijaCircle"];
My animation is not working and I don't know why...
I have this in my debug area:
2015-03-17 11:28:00.321 customControll[5759:325909] -[UIView cornerRadius]: unrecognized selector sent to instance 0x7fc79ac720c0
and my exception breakpoint os stoped on this part of pop framework:
{kPOPLayerCornerRadius,
^(CALayer *obj, CGFloat values[]) {
values[0] = [obj cornerRadius];// exception breakpoint is on this line here
},
^(CALayer *obj, const CGFloat values[]) {
[obj setCornerRadius:values[0]];
},
kPOPThresholdRadius}
You can also give me example of cornerRadius animation with pop that I can use, I just want to make it work with Facebook pop.
Thank you!

kPOPLayerCornerRadius is a layer property not a view property therefore you need to add the animation to the layer not the view. So this line:
[self.animationView pop_addAnimation:animationCircle forKey:#"animacijaCircle"];
should be:
[self.animationView.layer pop_addAnimation:animationCircle forKey:#"animacijaCircle"];

Related

What happened when block is declared as assign

I have been a while not tweaking blocks. Today I found one interview question about block in Objective-C:
Giving below code:
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIButton *button;
- (IBAction)buttonClick:(id)sender;
#property(nonatomic, assign) void(^block)();
#end
- (void)viewDidLoad {
[super viewDidLoad];
int value = 10;
void(^blockC)() = ^{
NSLog(#"just a block === %d", value);
};
NSLog(#"%#", blockC);
_block = blockC;
}
- (IBAction)buttonClick:(id)sender {
NSLog(#"Log:%#", _block);
}
What would happen?
Here's the output and some debug value:
If I add a breakpoint at the end of viewDidLoad(), here is the output:
2017-08-03 14:28:49.209 TestApp[23692:1211863] <__NSMallocBlock__: 0x600000055210>
(lldb) po _block
0x00000001026b86c0
And after I click the button and break at NSLog(#"Log:%#", _block);, it shows:
2017-08-03 14:30:57.948 TestApp[23692:1211863] Log:{(
_UILayoutGuide:0x7fc40b70cd10.minY{id: 16}
)}
(lldb) po _block
0x0000000000000003
So I kind of know that since blockC is freed after viewDidLoad(), _block should be pointing to a dirty field and cause memory leak or stack overflow. But what confuses me is that, first, in viewDidLoad(), why the NSLog output is <__NSMallocBlock__: 0x600000055210>, but the _block value is 0x00000001026b86c0? Does this mean whatever on 0x00000001026b86c0 is a pointer pointing to <__NSMallocBlock__: 0x600000055210>?
Secondly, when we click the button, why _block becomes 0x0000000000000003? It's not this value every time, sometimes could be 0x0000000000000001 and even other large numbers(or address value). Also how can NSLog output can be
Log:{(
_UILayoutGuide:0x7fc40b70cd10.minY{id: 16}?
)}
Can someone help explain the whole process? Thank in advance!

Why is UITextField text setter giving [UIView text] selector not recognized

I have this code:
- (IBAction)setButtonPressed:(id)sender {
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.TodayExtensionSharingDefaults.santiapps.com"];
NSLog(#"nsuserdef %#", [sharedDefaults objectForKey:#"MyNumberKey"]);
NSLog(#"self.textField.text %#", self.textField.text);
//[sharedDefaults setInteger:[self.textField.text integerValue] forKey:#"MyNumberKey"];
[sharedDefaults synchronize]; // (!!) This is crucial.
NSLog(#"syncd");
}
and for some reason when I tap the button, I get:
-[UIView text]: unrecognized selector sent to instance
but my property is set as:
#property (weak, nonatomic) IBOutlet UITextField *textField;
I get a crash if I uncommment the sharedDefaults setInteger line.
I get a crash if I leave the line where I read the self.textField.text.
I get the final syncd NSLog only if I comment-out the setInteger or self.textField.text NSLog lines.
Why is it thinking textField is a UIView without a text property?
Ok, don't mean to toot my own horn here, but I thought the answer might help someone.
Xcode had incorrectly linked my view controller's UIView to the outlet. And I know some will think I would have done it by being careless, except that I did it as I very seldomly do the connection:
I control dragged from the textfield to the assistant editor's interface where xcode itself created the IBOutlet UITextField for me. So I know it wasn't my mistake. :)
Xcode is buggy. So watch out :-)

NSInvalidArgumentException in Objective C

I'm making a simple calculator and when I use the addition button, the iOS Simulator crashes and I get an NSInvalidArgumentException. What do I do to prevent this from happening?
Error Report:
2013-06-23 17:18:54.574 Tutorial Test (Storyboard)[9744:c07] -[ViewController2 addition]:
unrecognized selector sent to instance 0x75858f0
2013-06-23 17:18:54.577 Tutorial Test (Storyboard)[9744:c07] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController2 addition]:
unrecognized selector sent to instance 0x75858f0'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x1d1c4bd 0x1c80bbc 0x1c8094e 0x10e2705 0x162c0 0x16258 0xd7021
0xd757f 0xd66e8 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962
0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x1e2d 0x1d55)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Code in ViewController that has this error:
View Controller.h
#import <UIKit/UIKit.h>
//Calculator
#interface ViewController2 : UIViewController{
IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
IBOutlet UILabel *label;
}
-(IBAction)addition;
-(IBAction)subtract;
-(IBAction)multiply;
-(IBAction)divide;
-(IBAction)clear;
#end
View Controller.m
//Addition
-(IBAction)plus
{
float a = ([textField1.text floatValue]);
float b = a+([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:#"%2.f", b];
}
You named the method in the .m file plus, rather than addition. That is why the method addition isn't found, and the fix would be to rename the method in the .m file from plus to addition:
//Addition
-(IBAction)addition
{
float a = [textField1.text floatValue];
float b = [textField2.text floatValue];
label.text = [[NSString alloc] initWithFormat:#"%2.f", a+b];
}
Have you allocated an instance of the ViewController2 class?
For example:
ViewController2 *vc2 = [[ViewController2 alloc] init];
[vc2 addition];
Also, if the .m code you posted is the full contents of that file, then you're also missing
-(IBAction)addition {
...
}
You didn't inplement the right method.
You call addition but you never actually implement it. Declaring the method signature in the .h is not enough, you have to code the method.
This means that the selector that you are calling is not available on the class you called it against. The best thing to do is place a breakpoint where the method is being called. Go to the debugger and po your object.
po 0x75858f0
in this instance. However that number could be an object and it could be different. Look at the number in the console.
Make sure the object is of the proper class. Then check that class to make sure it responds to the selector you are calling.
Edit: Your problem is that your plus method should be renamed to addition. The names in the .h must match the names in the .m

Unrecognized selector setting alpha for a UIImageView

I'm getting an unrecognized selector exception trying to set the alpha on a UIImageView, but I don't understand why this should be seeing a UIImageView inherits from UIView and alpha is a property of that.
#property (strong, nonatomic) IBOutlet UIImageView *pulldownTab;
...
self.pulldownTab.alpha = 1.0;
2013-05-21 07:33:32.964 TestControl[655:907] -[__NSCFNumber setAlpha:]: unrecognized selector sent to instance 0x1e587fa0
** UPDATE **
Moral of the story - Solved. be careful with key value coding, a call to this function was being made earlier
- (void) fadeToAlphaValue: (double) alpha forKeyPath: (NSString*) keyPath
{
NSNumber* number = [NSNumber numberWithDouble:alpha];
[UIView animateWithDuration:kFadeAnimationDuration
animations:^ {
[self setValue:number forKeyPath:keyPath];
}];
}
[self fadeToAlphaValue:0.0 forKeyPath:#"self.pulldownTab"];
Are you sure you are assigning the IBOutlet properly in the interface Builder?
The reference is not properly working, when you access to self.pulldownTab is accessing to a NSCFNumber variable in memory.
I had the same problem here. In my case, I was setting myTextView, but not the .text property, earlier in the code, like this:
self.myTextView = #"text";
instead of what I should have been doing:
self.myTextView.text = #"text";
for some reason this didn't throw any errors at this point, but it created an issue later when I tried to set the alpha property on an NSString (which doesn't have such a thing) :)
Anyways, just look for any stupid mistakes like this in your code before the .alpha property is being set - they'll likely be the cause of the problem!

How can I call a UIViewController method from an UIView subclass

I am developing and iOS app for iPad. I have an UIView subclass and I'd like to call a method of the ViewController from that subclass. I've tried to code a delegate but it doesn't work. Is that a good solution or I have to do it another way?
Try block, here is the sample:
MyView.h
#interface MyView: UIView
...
#property (nonatomic, copy) void(^myEventCallBack)(id someData);
...
#end
MyView.m
(How to call block sample)
...
- (IBAction)buttonTapped:(UIButton *)sender {
if (self.myEventCallback) {
self.myEventCallback(self.someImportantData);
}
}
...
in your UIViewController:
self.myView = [[MyView alloc] initWithFrame:someFrame];
// THIS IS VERY IMPORTANT, USE __weak COPY OF YOUR UIViewController OBJECT (owner of object which contains block) INSIDE BLOCK TO PREVENT RETAIN CIRCLE, CAUSE BLOCK RETAINS ITS CONTENT
__weak MyViewController *self_ = self;
self.myView.myEventCallback = ^(id someData){
[self_ doSomeProcessingWithData:someData];
};
also block can be used with return value, sample:
#property (nonatomic, copy) BOOL(^shouldStartProcessing)(void);
self.myView.myEventCallback = ^BOOL{
return (self_.state == MyViewControllerStateReady);
};
In general the problem of communication between conceptually "distant" objects is tricky one, but it is the heart of Cocoa programming. Getting a reference from one instance to another is crucial! I discuss the problem in general here:
http://www.apeth.com/iOSBook/ch13.html#_instance_visibility
Here's one possibility. If this UIView instance is in the interface, then either its nextResponder is the view controller or it is the subview of a superview whose nextResponder is the view controller. Moreover, the view hierarchy parallels the responder chain. So simply walk up the responder chain until you come to the view controller.
UIResponder* r = someView; // the view instance, living in the interface
while (![r isKindOfClass:[UIViewController class]])
r = [r nextResponder];
Now r is the view controller. Now cast to what you know is the actual view controller's class, and you will be able to call methods on it:
MyViewController* vc = (MyViewController*)r;
Here's my book's summary of the responder chain:
http://www.apeth.com/iOSBook/ch11.html#_the_responder_chain
However, there are many other possibilities. As someone has already suggested, you could set up lines of communication by means of NSNotification (shoutcasting); it's ugly, but it does work, and it's intended in part to cover just this sort of tricky situation.

Resources