we are using UISlider in our project, we are using that older in order to play audio.for specific audio, when we are playing that, UISlider is flickering for first 13 seconds. for another audio, that UISlider is flickering for first 8 seconds. what can be the solution for this? Thanks in advance.
I have assigned right value to the slider.
- (void)setSliderValue
{
if(self.jwAudioPlayer == nil)
return;
if(self.slider && self.slider.maximumValue == 1.0)
{
self.slider.minimumValue = 0.0;
self.slider.maximumValue = self.jwAudioPlayer.duration;
self.slider.value = 0;
}
}
- (void)setPlayerCurrentPlayingTime
{
if(self.jwAudioPlayer == nil)
return;
if(self.slider.maximumValue <= 0 && self.jwAudioPlayer.duration > 0){
self.slider.maximumValue = self.jwAudioPlayer.duration;
}
CGFloat durationInSeconds = self.jwAudioPlayer.duration;
CGFloat currentTimeInSeconds = self.jwAudioPlayer.position;
if(currentTimeInSeconds >= durationInSeconds)
{
currentTimeInSeconds = durationInSeconds;
[self pause];
}
if(self.durationTime)
{
self.durationTime.text = [self timeFormatted:durationInSeconds];
}
if(self.currentPlayingTime)
{
self.currentPlayingTime.text = [self timeFormatted:currentTimeInSeconds];
}
if(self.slider && self.slider.tag == 0)
{
[self setSliderValue];
[self.slider setValue:currentTimeInSeconds animated:YES];
}
if(self.playerController)
[self.playerController enableDisableSkipImage:currentTimeInSeconds];
Related
I have an animation that works fine in iOS 8 but not in iOS 7. In fact, it seems that sometimes, parts of the block are animated and parts are not (or maybe for different animation durations). It's quite hard to explain this.
__block BTQMenuItemView *previousToClose = nil;
[UIView animateWithDuration:(animated ? kAnimationDuration : 0.f) animations:^{
[_menuItemViews enumerateObjectsUsingBlock:^(BTQMenuItemView *current, NSUInteger idx, BOOL *stop) {
BTQMenuItemView *previous = (idx > 0 ? _menuItemViews[idx-1] : nil);
if(previous.expanded && sender == previous) {
current.top = current.savedFrame.origin.y + sender.item.contentView.height + (sender.item.titleView ? sender.item.titleView.height - sender.height : 0) + sender.item.marginTopContent;
sender.height += sender.item.contentView.height;
sender.height += sender.item.titleView.height;
sender.item.contentView.top = (sender.item.titleView ? sender.item.titleView.bottom : sender.titleLabel.bottom) + sender.item.marginTopContent;
sender.actionView.height += (sender.item.titleView ? sender.item.titleView.height - sender.actionView.height : 0);
} else {
if(previous.expanded) {
previous.height = previous.savedFrame.size.height;
previous.actionView.height = previous.titleLabel.height;
previous.expanded = NO;
previousToClose = previous;
}
current.height = current.savedFrame.size.height;
current.top = previous.bottom;
}
}];
BTQMenuItemView *lastView = [_menuItemViews lastObject];
_bottomCacheView.height = self.superview.height - self.top - lastView.bottom - _edgeInsets.bottom;
_bottomCacheView.top = lastView.bottom;
} completion:^(BOOL finished) {
BTQMenuItemView *lastView = [_menuItemViews lastObject];
self.height = lastView.bottom;
}];
[previousToClose iconWillOpen:NO];
I am calling a view with method;
[self.storyboard instantiateViewControllerWithIdentifier:];
Yesterday, this method was working well, but after some time something happened, it has stopped working.
I am using both xCode6 beta 6 and xcode5 v5.1.1
My code is as below, here all objects of an ViewController is nil?
What is wrong with this?
(IBAction)addTemplateViewPressed:(id)sender
{
PhotoTemplateViewController *templateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"photoTemplateViewController"];
//NSLog(#"%#",NSStringFromCGRect(templateVC.view.frame));
if(photoVerticalArray.count !=0 )
{
photoVerticalArray = [templateVC setVerticalImages:photoVerticalArray];
}
else
{
verticalFinished = true;
}
if(photoHorizontalArray.count !=0)
{
photoHorizontalArray = [templateVC setHorizontalImages:photoHorizontalArray];
}
else
{
horizontalFinished = true;
}
if(!verticalFinished && !horizontalFinished)
{
CGRect temp = templateVC.mainView.frame;
if(lastPosition == 0)
{
temp.origin.y = lastPosition = templateVC.mainView.frame.origin.y+48;
}
else
{
lastPosition = temp.origin.y= lastPosition + temp.size.height-4;
}
templateVC.view.frame = temp;
[mainView addSubview:templateVC.view];
NSLog(#"%#",NSStringFromCGSize(mainScrollView.contentSize));
[mainScrollView setContentSize:CGSizeMake(0, temp.origin.y+temp.size.height+50)];
NSLog(#"%#",NSStringFromCGSize(mainScrollView.contentSize));
}
I am trying to change a SKSpriteNode's texture while it is animated , but I faced with FPS dropping ! it goes down from 60 to 30 ! on both device and simulator ! the node is a parallel scrolling background , and here is the codes :
- (void)createBricksEdge {
brickEdges = [[SKSpriteNode alloc]initWithImageNamed:#"edge.png"];
brickEdges.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));;
brickEdges.name = #"edge";
[self addChild:brickEdges];
bEdge1 = [[SKSpriteNode alloc]initWithImageNamed:#"edge.png"];
bEdge1.position = CGPointMake(brickEdges.position.x,brickEdges.position.y+(brickEdges.size.height));
bEdge1.name = #"edge";
[self addChild:bEdge1];
}
moving background :
- (void)moveBg
{
[self enumerateChildNodesWithName:#"edge" usingBlock: ^(SKNode *node, BOOL *stop)
{
SKSpriteNode * bg = (SKSpriteNode *) node;
if (isSpeedBonus == YES) {
SPEED = 200;
} else {
switch (speedCriteria) {
case 0:
SPEED = 7.0;
break;
case 1:
SPEED = 11;
NSLog(#"FPS drops");
[bg runAction:[SKAction setTexture:[SKTexture textureWithImage:[UIImage imageNamed:#"edgeSpeed.png"]]]];
//I also tried : [bg setTexture:textre];
break;
.
.
.
.
.
}
}
bg.position = CGPointMake(bg.position.x , bg.position.y - SPEED);
if (bg.position.y <= -bg.size.width)
{ bg.position = CGPointMake(bg.position.x ,bg.position.y + bg.size.height*2); }} ];
}
Updating frames :
- (void)speedOMeter
{
int i = (int)[scoreLabel.text integerValue];
if (i <= 1000) {
speedCriteria = 0;
} else if (i <= 1500) {
speedCriteria = 1;
} else if (i <=2000) {
speedCriteria = 2;
} else if (i <= 2500) {
.
.
.
.
}
- (void)update:(CFTimeInterval)currentTime {
if (_lastUpdateTime)
{
_dt = currentTime - _lastUpdateTime;
}
else
{
_dt = 0;
}
_lastUpdateTime = currentTime;
[self moveBg]; [self speedOMeter];
}
You're bypassing the Sprite Kit caching mechanisms by creating the image first as a UIImage. This will load the image from disk, possibly every time:
[bg runAction:[SKAction setTexture:[SKTexture textureWithImage:[UIImage imageNamed:#"edgeSpeed.png"]]]];
Besides that you're overdoing it with the action. Try again with the simplified version that'll give you the same result by simply assigning the texture:
bg.texture = [SKTexture textureWithImageNamed:#"edgeSpeed.png"];
I have 10 fireflies that I make "fly" around the screen using the code below.
The code also serves to keep the fireflies on the screen.
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *blueArray = [NSArray array];
blueArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"blue1.png"],
[UIImage imageNamed:#"blue2.png"], nil];
blue.animationImages = blueArray;
blue.animationDuration = 0.20;
blue.animationRepeatCount = -1;
[blue startAnimating];
bluepos =CGPointMake(2.0, 1.5);
}
-(void) someMethod {
endingAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:(0.03) target:self selector:#selector(makeFly) userInfo:nil repeats:YES];
}
-(void) makeFly {
blue.center = CGPointMake(blue.center.x+bluepos.x, blue.center.y+bluepos.y);{
if(blue.center.x > 480 || blue.center.x <0)
bluepos.x = -bluepos.x;
if(blue.center.y > 320 || blue.center.y <0)
bluepos.y = -bluepos.y;
}
}
The "flying" works great except that when the fireflies hit the edge of the screen and reverse direction to keep them on the screen the firefly image itself is still "facing" the othe direction so it looks like they are flying backwards half the time.
I want to set it up so that when the fireflies hit the edge of the screen they reverse direction AND the image itself is reversed.
I tried this:
In .h
#property (nonatomic, assign) BOOL blueIsFacingRight;
In .m
#synthesize blueIsFacingRight;
-(void) makeFly {
blue.center = CGPointMake(blue.center.x+bluepos.x, blue.center.y+bluepos.y); {
if(blue.center.x > 480 ) {
if (blueIsFacingRight == YES) {
blue.transform = CGAffineTransformMakeScale(-1, 1);
blueIsFacingRight = NO;
}
bluepos.x = -bluepos.x;
}
if(blue.center.x <0) {
bluepos.x = -bluepos.x;
if (blueIsFacingRight == NO) {
blue.transform = CGAffineTransformMakeScale(1, 1);
blueIsFacingRight = YES;
}
}
if(blue.center.y > 320 )
bluepos.y = -bluepos.y;
if( blue.center.y <0)
bluepos.y = -bluepos.y;
}
}
I thought this would work but the image does not reverse when it hits the "wall"
Can anyone explain why this does not work and if there is a better why to accomplish the effect im looking for?
You are setting the transform X value to -1 in both cases. When its facing right you should set transform like this CGAffineTransformMakeScale(1, 1);
blue.center = CGPointMake(blue.center.x+bluepos.x, blue.center.y+bluepos.y); {
if(blue.center.x > 480 ) {
if (blueIsFacingRight == YES) {
blue.transform = CGAffineTransformMakeScale(-1, 1);
blueIsFacingRight = NO;
}
bluepos.x = -bluepos.x;
}
if(blue.center.x <0) {
bluepos.x = -bluepos.x;
if (blueIsFacingRight == NO) {
blue.transform = CGAffineTransformMakeScale(1, 1);
blueIsFacingRight = YES;
}
}
**blue.transform =CGAffineTransformIdentity;**
THe above was in my makeFly method with a bunch of other stuff above where I was reversing the image so I was undoing the change the very next time the method was called ( 0.03 later)
Man I feel stupid
I am using iOS 5 to implement an app.
In this app I have 4 button, each button triggers an animation to unhide a UIView. However, if I press a button and then another, the view that appeared first should disappear and the view for the new button would appear.
I have this working so far. But if the user taps two buttons rapidly it will display the two views. How can I insure that only once touch event is processed?
The action for the button is something like:
- (void)buttonPressed:(id)sender
{
MenuButton *aButton = (MenuButton *)sender;
switch (aButton.tag) {
case 0:
if (displayingView && currentlyDisplayingView != picker1)
[self toggleView:currentlyDisplayingView atIndex:currentIndex];
[self toggleView:picker1 atIndex:aButton.tag];
currentlyDisplayingView = picker1;
currentIndex = aButton.tag;
break;
case 1:
if (displayingView && currentlyDisplayingView != picker2)
[self toggleView:currentlyDisplayingView atIndex:currentIndex];
[self toggleView:picker2 atIndex:aButton.tag];
currentlyDisplayingView = picker2;
currentIndex = aButton.tag;
break;
case 2:
if (displayingView && currentlyDisplayingView != picker3)
[self toggleView:currentlyDisplayingView atIndex:currentIndex];
[self toggleView:picker3 atIndex:aButton.tag];
currentlyDisplayingView = picker3;
currentIndex = aButton.tag;
break;
default:
break;
}
NSLog(#"Pressed %#",[buttonNames objectAtIndex:aButton.tag]);
}
And the animation code:
- (void)toggleView:(UIView *)picker
atIndex:(NSInteger)index
{
if (picker) {
picker.hidden = NO;
[UIView animateWithDuration:0.5
animations:^{
picker.alpha = abs(picker.alpha - 1);
CGRect rect = picker.frame;
if (rect.size.height == 0){
rect.size.height = 76;
} else if (rect.size.height == 76) {
rect.size.height = 0;
}
picker.frame = rect;
for (int i = index+1; i < [viewButtons count]; i++) {
UIButton *aButton = [viewButtons objectAtIndex:i];
CGRect frame = aButton.frame;
if (rect.size.height == 0){
frame.origin.y -= 75;
} else if (rect.size.height == 76) {
frame.origin.y += 75;
}
aButton.frame = frame;
}
}
completion:^(BOOL success){
if (picker.alpha == 0){
picker.hidden = YES;
} else if (picker.alpha == 1) {
picker.hidden = NO;
}
displayingView = !displayingView;
}];
}
}
Call beginIgnoringInteractionEvents before calling animateWithDuration, and call endIgnoring... in the completion handler.