CABasicAnimation - animationDidStop not called - caanimation

I am making a CABasicAnimation and the problem is that the animationDidStop delegate method does not get called. I am not sure why but hopefully someone knows.
Here is my animation:
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath: #"transform.translation.x"];
theAnimation.duration = 54;
//theAnimation.repeatCount = 6;
theAnimation.autoreverses = YES;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat: (self.myImageView.frame.size.height / 5) + (self.view.frame.size.height - self.myImageView.center.x)];
theAnimation.toValue = [NSNumber numberWithFloat: 6.0 - (self.myImageView.frame.origin.y + self.myImageView.frame.size.height)];
//[self.myImageView.layer addAnimation:theAnimation forKey: #"animateLayer"];
[theAnimation setValue:#"Animation1" forKey:#"animateLayer"];
[[self.myImageView layer] addAnimation:theAnimation forKey:nil];
Also here is my animationDidStop method:
- (void)animationDidStop:(CABasicAnimation *)theAnimation finished:(BOOL)flag {
NSString* value = [theAnimation valueForKey:#"animateLayer"];
if ([value isEqualToString:#"Animation1"])
{
[self themethod];
return;
}
if ([value isEqualToString:#"Animation2"])
{
[self themethod];
return;
}
}
Does anyone knows why this is happening?

You need to set delegate to call animationDidStop.
theAnimation.delegate = class (self)

Related

Extension Autodesk Forge: My control panel doesn't connect to the Revit model after adding my own extension to the package

I used this package (https://github.com/petrbroz/forge-iot-extensions-demo). After that, I added my own extension code (RobotExt.js). The Control panel and Icon of the my extension were added to the Autodesk Forge website. But unfortunately, the control panel doesn't work.
There are these errors:
This is the source code of the my extension file:
class RobotExtension extends Autodesk.Viewing.Extension {
constructor(viewer, options) {
super(viewer, options);
this.viewer = viewer;
//this.tree = null;
this.tree = this.viewer.model.getData().instanceTree;
this.defaultState = null;
this.customize = this.customize.bind(this);
this.createUI = this.createUI.bind(this);
this.setTransformation = this.setTransformation.bind(this);
this.getFragmentWorldMatrixByNodeId = this.getFragmentWorldMatrixByNodeId.bind(this);
this.assignTransformations = this.assignTransformations.bind(this);
this.findNodeIdbyName = this.findNodeIdbyName.bind(this);
}
load() {
console.log('RobotExtension is loaded!');
this.createUI();
this.setTransformation();
return true;
}
unload() {
console.log('RobotExtension is now unloaded!');
this.viewer.restoreState(this.defaultState);
return true;
}
setTransformation() {
let tree = this.tree;
/* ====================== right 0 ================= */
let ID_BaseRod = 4806;
let ID_LowerArmBody = 4806;
let Pivot_BaseRod = new THREE.Mesh(new THREE.BoxGeometry(20, 20, 20), new THREE.MeshBasicMaterial({ color: 0xff0000 }));
let Position_BaseRod = this.getFragmentWorldMatrixByNodeId(ID_BaseRod).matrix[0].getPosition().clone();
//print the returned value from getFragmentWorldMatrixByNodeId method and using this we can inspect the....
// output of the fucntion(method) whether working or not
console.log(Position_BaseRod);
//console.log(position);
Pivot_BaseRod.position.x = 0;
Pivot_BaseRod.position.y = Position_BaseRod.y;
Pivot_BaseRod.position.z = Position_BaseRod.z-2.84;
viewer.impl.scene.add(Pivot_BaseRod);
let Helper_LowerArmBody = new THREE.Mesh();
let Position_LowerArmBody = this.getFragmentWorldMatrixByNodeId(ID_LowerArmBody).matrix[0].getPosition().clone();
Helper_LowerArmBody.position.x = - Position_LowerArmBody.x + Math.abs(Position_LowerArmBody.x - Pivot_BaseRod.position.x);
Helper_LowerArmBody.position.y = - Position_LowerArmBody.y + Math.abs(Position_LowerArmBody.y - Pivot_BaseRod.position.y);
Helper_LowerArmBody.position.z = - Position_LowerArmBody.z + Math.abs(Position_LowerArmBody.z - Pivot_BaseRod.position.z);
Pivot_BaseRod.add(Helper_LowerArmBody);
console.log(Position_LowerArmBody);
// // /* ====================== left 0 ================= */
let ID_BaseRod10 = 4851;
let ID_LowerArmBody10 = 4851;
let Pivot_BaseRod10 = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), new THREE.MeshBasicMaterial({ color: 0xff0000 }));
let Position_BaseRod10 = this.getFragmentWorldMatrixByNodeId(ID_BaseRod10).matrix[0].getPosition().clone();
//print the returned value from getFragmentWorldMatrixByNodeId method and using this we can inspect the....
// output of the fucntion(method) whether working or not
console.log(Position_BaseRod10);
Pivot_BaseRod10.position.x = 0;
Pivot_BaseRod10.position.y = Position_BaseRod10.y;
Pivot_BaseRod10.position.z = Position_BaseRod10.z-2.84;
viewer.impl.scene.add(Pivot_BaseRod10);
console.log(Pivot_BaseRod10);
let Helper_LowerArmBody10 = new THREE.Mesh();
let Position_LowerArmBody10 = this.getFragmentWorldMatrixByNodeId(ID_LowerArmBody10).matrix[0].getPosition().clone();
Helper_LowerArmBody10.position.x = Position_LowerArmBody10.x + Math.abs(Position_LowerArmBody10.x - Pivot_BaseRod10.position.x);
Helper_LowerArmBody10.position.y = -Position_LowerArmBody10.y + Math.abs(Position_LowerArmBody10.y - Pivot_BaseRod10.position.y);
Helper_LowerArmBody10.position.z = -Position_LowerArmBody10.z + Math.abs(Position_LowerArmBody10.z - Pivot_BaseRod10.position.z);
Pivot_BaseRod10.add(Helper_LowerArmBody10);
console.log(Position_LowerArmBody10);
let ID_BaseRod15 = 4886;
let ID_LowerArmBody15 = 4886;
let Pivot_BaseRod15= new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), new THREE.MeshBasicMaterial({ color: 0xff0000 }));
let Position_BaseRod15 = this.getFragmentWorldMatrixByNodeId(ID_BaseRod15).matrix[0].getPosition().clone();
//print the returned value from getFragmentWorldMatrixByNodeId method and using this we can inspect the....
// output of the fucntion(method) whether working or not
console.log(Position_BaseRod15);
Pivot_BaseRod15.position.x = 0;
Pivot_BaseRod15.position.y = Position_BaseRod15.y;
Pivot_BaseRod15.position.z = Position_BaseRod15.z-2.84;
viewer.impl.scene.add(Pivot_BaseRod15);
console.log(Pivot_BaseRod15);
let Helper_LowerArmBody15 = new THREE.Mesh();
let Position_LowerArmBody15 = this.getFragmentWorldMatrixByNodeId(ID_LowerArmBody15).matrix[0].getPosition().clone();
Helper_LowerArmBody15.position.x = Position_LowerArmBody15.x + Math.abs(Position_LowerArmBody15.x - Pivot_BaseRod15.position.x);
Helper_LowerArmBody15.position.y = -Position_LowerArmBody15.y + Math.abs(Position_LowerArmBody15.y - Pivot_BaseRod15.position.y);
Helper_LowerArmBody15.position.z = -Position_LowerArmBody15.z + Math.abs(Position_LowerArmBody15.z - Pivot_BaseRod15.position.z);
Pivot_BaseRod15.add(Helper_LowerArmBody15);
console.log(Position_LowerArmBody15);
There was an error for limitation character in Stackoverflow I had to delete some parts of my code.
[![enter image description here][2]][2]
In the setTransformation method of your extension class, you have the following line of code:
viewer.impl.scene.add(Pivot_BaseRod1);
The viewer variable is not defined, however. The line of code should instead look like this:
this.viewer.impl.scene.add(Pivot_BaseRod1);

how to hide Empty UITableViewcell Label with using json?

hi i need to hide empty UITableViewcell label in custom TableView.i am trying to display JSON webservice values in custom tableviewcell.
my json vales are looks like ...
(
{
post = {
"CLASS_LEVEL" = "Intro/General";
"CLASS_TYPE" = "Muay Thai";
"DAY_OF_WEEK" = "";
ID = 19;
"ORDER_BY" = 5;
TIME = "1:00pm - 2:30pm";
};
}
{
post = {
"CLASS_LEVEL" = "General/Intermediate/Advanced";
"CLASS_TYPE" = "Muay Thai Spar - Competitive";
"DAY_OF_WEEK" = "";
ID = "";
"ORDER_BY" = 5;
TIME = "6:00pm - 9:00pm";
};
},
{
post = {
"CLASS_LEVEL" = "Fighters/Advanced/Intermediate";
"CLASS_TYPE" = "Fighters Training";
"DAY_OF_WEEK" = Monday;
ID = 1;
"ORDER_BY" = 1;
TIME = "";
};
},
i need to auto size my table cell dynamically .
here some of values are empty that values assigned label in tableviewcell want to be hidden.
is it possible? help me .Thanks in advance
To hide the UILabel you can just do cell.label.hidden = YES;
You can try this
NSString *dayOfWeek = ... ;
if(dayOfWeek == (id) [NSNull null] || [dayOfWeek length] == 0 || [dayOfWeek isEqualToString:#""])
{
cell.label.hidden = YES;
}
else
{
cell.label.hidden = NO;
}

UIWebView: get attributes from hyperlink clicked

I have html page loaded via UIWebView. If user selects link that looks like:
<a webview="2" href="#!/accounts-cards/<%= item.acctno %>"></a>
I can get href value clicked in UIWebViewDelegate method from NSURLRequest:
webView:shouldStartLoadWithRequest:navigationType:
But how I can get attribute value from this hyperlink (webview="2") assuming that attribute name "webview" determined?
You can get your attribute "webview", with the help of JavaScript and after that you can send that attribute and its value to native Objective C code.
Add this JavaScript code to your HTML page inside script tag:
function reportBackToObjectiveC(string)
{
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "callback://" + string);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
var links = document.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
links[i].addEventListener("click", function() {
var attributeValue=links[i].webview; //this will give you your attribute(webview) value.
reportBackToObjectiveC(attributeValue);
}, true);
}
after this your webViewDelegate method will call:
- (BOOL)webView:(UIWebView *)wView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
NSURL *URL = [request URL];
if ([[URL scheme] isEqualToString:#"callback"])
{
//You can get here your attribute's value.
}
}
You need to change href of your links. First inject javascript script, that patches your links.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *js = #"var allElements = document.getElementsByTagName('a');"
"for (var i = 0; i < allElements.length; i++) {"
" attribute = allElements[i].getAttribute('webview');"
" if (attribute) {"
" allElements[i].href = allElements[i].href + '&' + attribute;"
" }"
"}";
[webView stringByEvaluatingJavaScriptFromString:js];
}
Links will be converted into format (note &2 in href attribute):
<a webview="2" href="#!/accounts-cards/<%= item.acctno %>&2"></a>
Then you can get your callback and parse you webview param value:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSArray *array = [request.URL.absoluteString componentsSeparatedByString:#"&"];
if (array.count > 2) {
NSLog(#"webview value = %#", array[1]);
}
return YES;
}

How to encode odd HTML characters with Xcode?

I need to save a HTML page in my app, and when characters like "€" are found, the saved file displays them wrong.
I tried several encodings but none solves this, is there any solution?
I have also tried to replace the characters for the HTML name, but it still doesn't work.
Here's my code:
NSString *HTML = [web stringByEvaluatingJavaScriptFromString:#"document.getElementsByTagName('html')[0].innerHTML;"];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:#"%#/%#", [path objectAtIndex:0],#"code.html"];
int enc_arr[] = {
NSISOLatin1StringEncoding, // ESP
NSUTF8StringEncoding, // UTF-8
NSShiftJISStringEncoding, // Shift_JIS
NSJapaneseEUCStringEncoding, // EUC-JP
NSISO2022JPStringEncoding, // JIS
NSASCIIStringEncoding // ASCII
};
NSData *urlData= nil;
for (int i=0; i<6; i++) {
urlData = [HTML dataUsingEncoding:enc_arr[i]];
if (urlData!=nil) {
break;
}
}
[urlData writeToFile:filePath atomically:YES];
See these methods of NSString:
- (NSStringEncoding)smallestEncoding
- (NSStringEncoding)fastestEncoding
or just use method below with flag set to YES :
- (NSData *)dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)flag
but with this one you can loose some characters.
Ok I finally did it, it's not the best way but the only one that worked for me and without using external libraries:
-(NSString*)escapeHTML:(NSString*)code{
NSMutableArray *maExceptions = [[NSMutableArray alloc] initWithObjects: #"Œ", #"œ", #"Š", #"š", #"Ÿ", #"ƒ", #"‘", #"’", #"‚", #"“", #"”", #"„", #"†", #"‡", #"•", #"…", #"‰", #"€", #"™", nil];
for (int i=0; i<[maExceptions count]; i++) {
code = [code stringByReplacingOccurrencesOfString:[maExceptions objectAtIndex:i] withString:[NSString stringWithFormat:#"&#x%x;",[[maExceptions objectAtIndex:i] characterAtIndex:0]]];
}
return code;
}

Three20 Navigation: View don't show

I rework my app to use Three20 and I wanna use Three20 navigation now.
Here is my code, that works perfectly before:
ENSListViewController *vc = [ENSListViewController alloc];
NSArray *ensArray;
NSDictionary *dic;
NSInteger folder_id;
NSString* folder_type;
NSString* barTitle;
NSString* folderName;
if (indexPath.section == 0)
{
ensArray = [ensFolderList objectForKey:#"an"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"an";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
else
{
ensArray = [ensFolderList objectForKey:#"von"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"von";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
vc.folder_id = folder_id;
vc.folder_type = folder_type;
vc.barTitle = barTitle;
vc.folderName = folderName;
[vc initWithNibName:#"ENSListViewController" bundle:nil];
[self.view addSubview:vc.view];
It works perfectly.
It allocs a ViewController, sets a lot of data in the ViewController (Properties) and then show the view.
Here is my code now:
NSArray *ensArray;
NSDictionary *dic;
NSInteger folder_id;
NSString* folder_type;
NSString* barTitle;
NSString* folderName;
if (indexPath.section == 0)
{
ensArray = [ensFolderList objectForKey:#"an"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"an";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
else
{
ensArray = [ensFolderList objectForKey:#"von"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"von";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
/*
vc.folder_id = folder_id;
vc.folder_type = folder_type;
vc.barTitle = barTitle;
vc.folderName = folderName;
[vc initWithNibName:#"ENSListViewController" bundle:nil];
//[self.view addSubview:vc.view];
*/
NSString *url = [NSString stringWithFormat:#"tt://ensList/%#/%#/%d/%#/%#/%#", #"ENSListViewController", nil, folder_id, folder_type, barTitle, folderName];
TTURLAction *action = [TTURLAction actionWithURLPath:url];
[[TTNavigator navigator] openURLAction:action];
Here is my Navigator:
navigator = [TTNavigator navigator]; // create the navigator
navigator.persistenceMode = TTNavigatorPersistenceModeAll; // and he will save the data :)
TTURLMap* map = navigator.URLMap;
[map from: #"tt://ens"
toSharedViewController: [ENSOverviewViewController class]];
[map from: #"tt://ensList/(initWithNibName:)/(bundle:)/(folderId:)/(folderType:)/(barTitle:)/(folderName:)" toViewController:[ENSListViewController class]
transition:3];
And here is my new Constructor method:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self LoadENSList];
}
return self;
}
- (void) initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil folderId:(NSInteger)folder_id2 folderType:(NSString*)folder_type2 barTitle:(NSString*)barTitle2 folderName:(NSString*)folderName2
{
self.folder_id = folder_id2;
self.folder_type = folder_type2;
self.barTitle = barTitle2;
self.folderName = folderName2;
[self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
}
So, if you read it up to here: big thanks!
Now my problem is: The view doesn't open. Nothing happens.
I think there is a mistake in my self made constructor, the order of calling my constructor or something like this. Im on it since 2 hours but can't find the error.
I know Three20 is much undocumented and I am not expacting a fast answer, but if anyone have an idea: please comment or answer.
Found the solution:
1) I forget the return-value in my constructur.
After adding this (changing (void) to (id) and add "return self") it goes on...
2) After he changes in 1) the system crashes because initWithNibName throws an NSInvalidArgument error.
After changing this to init, it works perfectly