Avsession gives "Memory warning " - ios

I am using Avsession to capture images .
while i capture first image i will redirect user to apply effects on it and then get back to my capture image screen and i will preview image on cam capture screen .Then i will allow user to capture 3 more images and i will preview all images on cam capture screen. while i capturing my third image i will receive memory warning.
After Capturing Every image i will crop image to resize.
I have write below code in viewdidload
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch] && [device hasFlash]){
[device lockForConfiguration:nil];
[device setTorchMode:cameraFlashMode];
[device unlockForConfiguration];
[self.btnFlashLight setHidden:NO];
}
else
[self.btnFlashLight setHidden:YES];
cameraMode = AVCaptureDevicePositionBack;
firstImage.layer.borderWidth = 2.0f;
firstImage.layer.borderColor = [UIColor grayColor].CGColor;
secondImage.layer.borderWidth = 2.0f;
secondImage.layer.borderColor = [UIColor grayColor].CGColor;
thirdImage.layer.borderWidth = 2.0f;
thirdImage.layer.borderColor = [UIColor grayColor].CGColor;
forthImage.layer.borderWidth = 2.0f;
forthImage.layer.borderColor = [UIColor grayColor].CGColor;
if ([capturedImages count] == 0)
[self.btnNext setEnabled:NO];
if ([self captureManager] == nil) {
CamCaptureManager *manager = [[CamCaptureManager alloc] init];
[self setCaptureManager:manager];
[[self captureManager] setDelegate:self];
if ([[self captureManager] setupSession]) {
// Create video preview layer and add it to the UI
newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[newCaptureVideoPreviewLayer setFrame:bounds];
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
UIBezierPath *fullScreenPath = [UIBezierPath bezierPathWithRect:view.bounds];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
[fullScreenPath appendPath:[UIBezierPath bezierPathWithRoundedRect:[GeneralDeclaration generalDeclaration].cameraMaskFrame byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(0.0f, 0.0f)]];
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskLayer.path = fullScreenPath.CGPath;
maskLayer.fillColor = [UIColor blackColor].CGColor;
maskLayer.opacity = 0.6f;
maskLayer.lineWidth = 1.0f;
maskLayer.strokeColor = [UIColor whiteColor].CGColor;
[viewLayer insertSublayer:maskLayer above:[[viewLayer sublayers] objectAtIndex:0]];
[self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];
[[self captureManager] session ].sessionPreset = AVCaptureSessionPresetPhoto;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[[self captureManager] session] startRunning];
});
}
}
I have written Below code to process captured Image:
[[self captureManager] captureStillImage];
UIView *flashView = [[UIView alloc] initWithFrame:[[self videoPreviewView] frame]];
[flashView setBackgroundColor:[UIColor whiteColor]];
[[[self view] window] addSubview:flashView];
[UIView animateWithDuration:.4f
animations:^{
[flashView setAlpha:0.f];
}
completion:^(BOOL finished){
[flashView removeFromSuperview];
}
];
firstImage.image = nil;
secondImage.image = nil;
thirdImage.image = nil;
forthImage.image = nil;
//firstImage.userInteractionEnabled = YES;
secondImage.userInteractionEnabled = YES;
thirdImage.userInteractionEnabled = YES;
forthImage.userInteractionEnabled = YES;
for (UIImageView *subview in [firstImage subviews]) {
[subview removeFromSuperview];
}
for (UIImageView *subview in [secondImage subviews]) {
[subview removeFromSuperview];
}
for (UIImageView *subview in [thirdImage subviews]) {
[subview removeFromSuperview];
}
for (UIImageView *subview in [forthImage subviews]) {
[subview removeFromSuperview];
}
for(int i = 0; i < [capturedImages count]; i++)
{
UIImage *removeImage = [UIImage imageNamed:#"remove_image.png"];
UIImageView *removeImageView = [[UIImageView alloc] initWithImage:removeImage];
removeImageView.tag = i;
[removeImageView setCenter:CGPointMake(firstImage.bounds.size.width/2, firstImage.bounds.size.height/2)];
UITapGestureRecognizer *removeImageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(removeImage_Tapped:)];
removeImageTap.numberOfTapsRequired = 1;
removeImageView.userInteractionEnabled = YES;
[removeImageView addGestureRecognizer:removeImageTap];
switch (i) {
case 0:
firstImage.image = [capturedImages objectAtIndex:i];
//[firstImage addSubview:removeImageView];
break;
case 1:
secondImage.image = [capturedImages objectAtIndex:i];
[secondImage addSubview:removeImageView];
break;
case 2:
thirdImage.image = [capturedImages objectAtIndex:i];
[thirdImage addSubview:removeImageView];
break;
case 3:
forthImage.image = [capturedImages objectAtIndex:i];
[forthImage addSubview:removeImageView];
break;
default:
break;
}
}
Please help me to solve.

Set property sessionPreset like this:
[yourcamera session].sessionPreset = AVCaptureSessionPresetHigh
This will not totally remove memory warning but may help to reduce it.

Related

Why is this animation not working as intended?

Hi there all the past couple days now I’ve been trying to modify the iOS tweak Daisy. I have successfully added more fonts, make the Hello animation stay on the screen and merged a closed pull request that the original dev didn’t want In. Anyways I’m up to trying to fix this bug that the original version has and that is that the “playHelloStartAnimation” will bug out sometimes when waking the phone. Sometimes it will fully replay the animation from the beginning or a couple frames from the middle of the animation, other times it will finish and show nothing for a few millisecond and then continue to the next animation or will play as intended. Tried adding a blank animation to play first so when it dose bug out you’ll won’t see but didn’t help, change times, tried other hooks still happens. Can’t figure out why any help would be appreciated.
%group DiaryHello
%hook CSCoverSheetView
%property(nonatomic, retain)UIView* diaryHelloIconView;
%property(nonatomic, retain)UILabel* diaryHelloLabel;
- (void)didMoveToWindow { // add iphone hello
%orig;
// hello label
if (enableHelloSwitch && showHelloGreetingSwitch && ![self diaryHelloLabel]) {
self.diaryHelloLabel = [UILabel new];
[[self diaryHelloLabel] setTextColor:[UIColor whiteColor]];
if ([fontFamilyValue intValue] == 0) [[self diaryHelloLabel] setFont:[UIFont fontWithName:#"Selawik-Regular" size:24]];
else if ([fontFamilyValue intValue] == 1) [[self diaryHelloLabel] setFont:[UIFont systemFontOfSize:24 weight:UIFontWeightRegular]];
[[self diaryHelloLabel] setText:greetingValue];
[[self diaryHelloLabel] setTextAlignment:NSTextAlignmentCenter];
[[self diaryHelloLabel] setAlpha:0];
[[self diaryHelloLabel] setHidden:YES];
[self addSubview:[self diaryHelloLabel]];
[[self diaryHelloLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint activateConstraints:#[
[self.diaryHelloLabel.topAnchor constraintEqualToAnchor:self.topAnchor constant:150],
[self.diaryHelloLabel.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[self.diaryHelloLabel.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
]];
}
}
%new
- (void)initHelloViewWithAnimation:(int)animation { // set hello view up
if (!enableHelloSwitch) return;
if (enableMediaPlayerSwitch && ![[self diaryPlayerView] isHidden]) return;
[[self diaryHelloIconView] stopAnimating];
[[self diaryHelloIconView] removeFromSuperview];
self.diaryHelloIconView = nil;
if (animation == 0) {
helloStartArray = [NSMutableArray new];
for (int i = 0; i < 24; i++) [helloStartArray addObject:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"/Library/PreferenceBundles/DiaryPreferences.bundle/hello/start/%i.png", i]]];
helloStartImage = [UIImage animatedImageWithImages:helloStartArray duration:0.6];
self.diaryHelloIconView = [[UIImageView alloc] initWithImage:helloStartImage];
helloSearchingArray = nil;
helloSearchingImage = nil;
helloAuthenticatedArray = nil;
helloAuthenticatedImage = nil;
} else if (animation == 1) {
helloSearchingArray = [NSMutableArray new];
for (int i = 0; i < 116; i++) [helloSearchingArray addObject:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"/Library/PreferenceBundles/DiaryPreferences.bundle/hello/searching/%i.png", i]]];
helloSearchingImage = [UIImage animatedImageWithImages:helloSearchingArray duration:4.28];
self.diaryHelloIconView = [[UIImageView alloc] initWithImage:helloSearchingImage];
helloStartArray = nil;
helloStartImage = nil;
helloAuthenticatedArray = nil;
helloAuthenticatedImage = nil;
} else if (animation == 2) {
helloAuthenticatedArray = [NSMutableArray new];
for (int i = 0; i < 51; i++) [helloAuthenticatedArray addObject:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"/Library/PreferenceBundles/DiaryPreferences.bundle/hello/authenticated/%i.png", i]]];
helloAuthenticatedImage = [UIImage animatedImageWithImages:helloAuthenticatedArray duration:1.12];
self.diaryHelloIconView = [[UIImageView alloc] initWithImage:helloAuthenticatedImage];
helloStartArray = nil;
helloStartImage = nil;
helloSearchingArray = nil;
helloSearchingImage = nil;
}
[[self diaryHelloIconView] setContentMode:UIViewContentModeScaleAspectFit];
[[self diaryHelloIconView] setClipsToBounds:YES];
[[self diaryHelloIconView] setHidden:NO];
if (![[self diaryHelloIconView] isDescendantOfView:self]) [self addSubview:[self diaryHelloIconView]];
[[self diaryHelloIconView] setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint activateConstraints:#[
[self.diaryHelloIconView.topAnchor constraintEqualToAnchor:self.topAnchor constant:50],
[self.diaryHelloIconView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
[self.diaryHelloIconView.heightAnchor constraintEqualToConstant:80],
[self.diaryHelloIconView.widthAnchor constraintEqualToConstant:80],
]];
}
%new
- (void)playHelloStartAnimation { // play hello start animation
if (!enableHelloSwitch) return;
if (enableMediaPlayerSwitch && ![[self diaryPlayerView] isHidden]) return;
shouldPlaySearchAnimation = YES;
[self initHelloViewWithAnimation:0];
[[self diaryHelloIconView] setAnimationRepeatCount:1];
[[self diaryHelloIconView] startAnimating];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self playHelloSearchingAnimation];
});
}
%new
- (void)playHelloSearchingAnimation { // play hello searching animation
if (!enableHelloSwitch) return;
if (enableMediaPlayerSwitch && ![[self diaryPlayerView] isHidden]) return;
if (!shouldPlaySearchAnimation) return;
[self initHelloViewWithAnimation:1];
[[self diaryHelloIconView] setAnimationRepeatCount:0];
[[self diaryHelloIconView] startAnimating];
if (showHelloGreetingSwitch) [[self diaryHelloLabel] setAlpha:0];
}
%new
- (void)playHelloAuthenticatedAnimation { // play hello authenticated animation
if (!enableHelloSwitch) return;
if (enableMediaPlayerSwitch && ![[self diaryPlayerView] isHidden]) return;
shouldPlaySearchAnimation = NO;
[self initHelloViewWithAnimation:2];
[[self diaryHelloIconView] setAnimationRepeatCount:1];
[[self diaryHelloIconView] startAnimating];
if (showHelloGreetingSwitch) {
NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
[UIView animateWithDuration:0.25 delay:0.4 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[[self diaryHelloLabel] setHidden:NO];
[[self diaryHelloLabel] setAlpha:1];
[notificationCenter postNotificationName:#"diaryUpdateNotificationList" object:nil];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[[self diaryHelloLabel] setAlpha:0];
} completion:^(BOOL finished) {
[[self diaryHelloIconView] setHidden:YES];
[[self diaryHelloLabel] setHidden:YES];
[[self diaryHelloIconView] removeFromSuperview];
[notificationCenter postNotificationName:#"diaryUpdateNotificationList" object:nil];
}];
}];
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.8 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[[self diaryHelloIconView] setHidden:YES];
[[self diaryHelloIconView] removeFromSuperview];
[[NSNotificationCenter defaultCenter] postNotificationName:#"diaryUpdateNotificationList" object:nil];
});
}
}
%end
%hook CSCoverSheetViewController
- (void)viewDidDisappear:(BOOL)animated { // remove hello view when lock screen disappeared
%orig;
// free up memory when hello is not visible
[[coverSheetView diaryHelloIconView] stopAnimating];
[[coverSheetView diaryHelloIconView] removeFromSuperview];
helloStartArray = nil;
helloStartImage = nil;
helloSearchingArray = nil;
helloSearchingImage = nil;
helloAuthenticatedArray = nil;
helloAuthenticatedImage = nil;
}
%end
%hook SBLockScreenManager
- (void)lockUIFromSource:(int)arg1 withOptions:(id)arg2 { // remove hello view when device was locked
%orig;
// free up memory when hello is not visible
isLockedHello = YES;
isScreenOnHello = NO;
[[coverSheetView diaryHelloIconView] stopAnimating];
[[coverSheetView diaryHelloIconView] removeFromSuperview];
helloStartArray = nil;
helloStartImage = nil;
helloSearchingArray = nil;
helloSearchingImage = nil;
helloAuthenticatedArray = nil;
helloAuthenticatedImage = nil;
}
%end
%hook SBBacklightController
- (void)turnOnScreenFullyWithBacklightSource:(long long)arg1 { // update diary when screen turns on
%orig;
if (![[%c(SBLockScreenManager) sharedInstance] isLockScreenVisible]) return; // this method gets called not only when the screen gets turned on, so i verify that it was turned on by checking if the lock screen is visible
if (!isScreenOnHello) [coverSheetView playHelloStartAnimation];
[[NSNotificationCenter defaultCenter] postNotificationName:#"diaryUpdateNotificationList" object:nil];
isScreenOnHello = YES;
}
%end
%hook SBDashBoardBiometricUnlockController
- (void)setAuthenticated:(BOOL)arg1 { // play authenticated animation when unlocked with biometrics
%orig;
if (arg1 && isLockedHello) {
isLockedHello = NO;
[coverSheetView playHelloAuthenticatedAnimation];
}
}
%end
%end
Original tweaks source code: https://github.com/schneelittchen/Diary

Horizontal scrolling on a view in ios [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How can I implement scroll view to horizontally scroll the view pages loaded from a NSDictionary. Presently i am using swipegesture but that is little slow.
What code should I implement to achieve horizontal scrolling?
i am using this code:
-(void)DownLoadData:(NSString *)indexSelect
{
{
[[SharedUtilities getInstance]AddActivityIndicatorViewOnMainThread:self.view];
}
self._parserForNewsDetail = [afaqsParser getInstance];
[[afaqsParser getInstance] setCacheNeed:TRUE];
[self._parserForNewsDetail parseWithUrl:[_arrUrlLinks objectAtIndex:[indexSelect integerValue]] UrlTypefor:nil];
NSDictionary *resultDic;
resultDic = [[[self._parserForNewsDetail getLinkAndIdDic] valueForKey:#"items"]objectAtIndex:0];
NSLog(#"Detail Dic = %#",[resultDic description]);
if (resultDic== NULL || resultDic ==nil)
{
//Check internet here
[[SharedUtilities getInstance]RemoveActivityIndicatorView];
[SharedUtilities ShowAlert:#"No Data Found" title:nil withView:self.view];
return;
}
[self performSelectorOnMainThread:#selector(SetValuesInUserInterface:) withObject: resultDic waitUntilDone:NO];
[[SharedUtilities getInstance]RemoveActivityIndicatorView];
}
-(void)SetValuesInUserInterface:(NSDictionary *)Dic
{
self._imageView1.layer.cornerRadius = 4;
self._imageView1.clipsToBounds = YES;
self._imageView1.tag = 999;
NSURL *imgurl =[NSURL URLWithString:[[Dic valueForKey:#"image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
self._imageView1.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:imgurl]];
NSArray *subviewsArr = [self.view subviews];
for (int i=0; i<[subviewsArr count]; i++) {
if ([[subviewsArr objectAtIndex:i] isKindOfClass:[ImageDownLoader class]]) {
[[subviewsArr objectAtIndex:i] removeFromSuperview];
}
}
if ([[Dic valueForKey:#"image"] isEqual:#""])
{
// strg=[NSString stringWithFormat:#"%#, ",[Dic valueForKey:#"image"]];
_imageView1.hidden=YES;
// _txtView.frame=CGRectMake(4.0f,95.0f,310.0f,100.0f );
_txtView.frame=CGRectMake(4.0f,95.0f,_txtView.frame.size.width,_txtView.frame.size.height );
NSLog(#"NO IMAGE");
}
else{
_imageView1.hidden=NO;
_imageView1.frame=CGRectMake(4.0f,95.0f,310.0f,180.0f );
_txtView.frame=CGRectMake(4.0f,316.0f,_txtView.frame.size.width,_txtView.frame.size.height );
NSLog(#"IMAGE VISIBLE");
}
self._scrollView.scrollEnabled = YES;
self._scrollView.showsVerticalScrollIndicator = YES;
self._scrollView.showsHorizontalScrollIndicator = YES;
self._header.font = [UIFont fontWithName:#"HelveticaNeue-MediumCond" size:18];
[self._header setText: [Dic valueForKey:#"header"]];
self._header.textColor=[UIColor blackColor];
[self._publicationDate setText:[Dic valueForKey:#"PUB_DATE"]];
[self._kicker setText:[Dic valueForKey:#"kicker"]];
[self._txtView setText:[Dic valueForKey:#"ARTICLE_BODY"]];
NSString *writer;
if ([[Dic valueForKey:#"AUTHOR"] length]>2)
{
writer=[NSString stringWithFormat:#"%#, ",[Dic valueForKey:#"AUTHOR"]];
}
else
{
writer=#"";
}
NSString *city;
if ([[Dic valueForKey:#"REPORTING_CITY"] length]>2)
{
city=[NSString stringWithFormat:#", %#",[Dic valueForKey:#"REPORTING_CITY"]];
}
else
{
city=#"";
}
NSString *str = [NSString stringWithFormat:#"%#ee%#", writer,city];
//[cell._Writer setText: [tempDic valueForKey:#"writer"]];
[self._Writer setText:str];
[_txtView sizeToFit]; //added
[_txtView layoutIfNeeded]; //added
CGRect frame = self._txtView.frame;
self._txtView.frame = frame;
[_txtView setScrollEnabled:NO];
self._scrollView.contentSize = CGSizeMake(320,440+frame.size.height);
_titleLabel.frame= CGRectMake(0, self._scrollView.contentSize.height-119, [[UIScreen mainScreen] bounds].size.width, 40);
_titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:1];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.font = [UIFont fontWithName:#"Helvetica" size:13.5];
_titleLabel.numberOfLines=2;
[self._scrollView addSubview:_titleLabel];
}
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_titleLabel = [[UILabel alloc] init];
lblTitle.font = [UIFont fontWithName:#"HelveticaNeue-MediumCond" size:20];
lblTitle.text=_strTitle;
NSLog(#"arrUrls %d",[_arrUrlLinks count]);
NSLog(#"strCurrentNewsSelect %#",_strCurrentNewsSelect);
[[NSNotificationCenter defaultCenter]
postNotificationName:#"DISABLEGESTURE"
object:self];
count=[_strCurrentNewsSelect integerValue];
[self performSelectorInBackground:#selector(DownLoadData:) withObject:_strCurrentNewsSelect];
if([_strCurrentNewsSelect isEqualToString:#"0"])
{
btnPreviousNews.userInteractionEnabled=FALSE;
}
else{
}
_lblNewsCount.font = [UIFont fontWithName:#"HelveticaNeue-MediumCond" size:16];
_lblNewsCount.text=[NSString stringWithFormat:#"%d/%d",[_strCurrentNewsSelect integerValue]+1,[_arrUrlLinks count]];
// Do any additional setup after loading the view from its nib.
UIButton *shareBtn = [[UIButton alloc]initWithFrame:CGRectMake(280, 340, 40, 40)];
[shareBtn addTarget:self action:#selector(Share:) forControlEvents:UIControlEventTouchUpInside];
[shareBtn setBackgroundImage:[UIImage imageNamed:#"share1.png"] forState:UIControlStateNormal];
// [self.view addSubview:shareBtn];
if([_strCurrentNewsSelect isEqualToString:#"0"])
{
btnPreviousNews.userInteractionEnabled=FALSE;
[btnPreviousNews setImage:[UIImage imageNamed:#"arrow2_prev.png"] forState:UIControlStateNormal];
}
if([_strCurrentNewsSelect isEqualToString:[NSString stringWithFormat:#"%d",[_arrUrlLinks count]-1]])
{
btnNextNews.userInteractionEnabled=FALSE;
[btnNextNews setImage:[UIImage imageNamed:#"arrow2_next.png"] forState:UIControlStateNormal];
}
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
//add the your gestureRecognizer , where to detect the touch..
[_scrollView addGestureRecognizer:rightRecognizer];
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[_scrollView addGestureRecognizer:leftRecognizer];
}
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
[self btnPreviousClick];
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(#"leftSwipeHandle");
[self btnNextClick];
}
-(IBAction)Share:(UIButton *)sender
{
NSLog(#"SHare called =%d",sender.tag);
// NSDictionary *tempDic = [[self._resultDic valueForKey:#"items"] objectAtIndex:sender.tag];
[[SharedUtilities getInstance] set_LinkForSharing:[[[[self._parserForNewsDetail getLinkAndIdDic] valueForKey:#"items"]objectAtIndex:0] valueForKey:#"image"]];
[[SharedUtilities getInstance]set_headerForSharing:[[[[self._parserForNewsDetail getLinkAndIdDic] valueForKey:#"items"]objectAtIndex:0] valueForKey:#"header"]];
[[SharedUtilities getInstance]set_viewController:self];
[[SharedUtilities getInstance]Share];
}
-(IBAction)btnBackPress:(id)sender;
{
[[NSNotificationCenter defaultCenter]
postNotificationName:#"ENABLEGESTURE"
object:self];
[self.navigationController popViewControllerAnimated:YES];
lblTitle.text=_strTitle;
}
-(IBAction)btnNextClick
{
btnPreviousNews.userInteractionEnabled=TRUE;
if(count!=[_arrUrlLinks count] -1)
{
if(count==[_arrUrlLinks count]-2)
{
btnNextNews.userInteractionEnabled=FALSE;
[btnNextNews setImage:[UIImage imageNamed:#"arrow2_next.png"] forState:UIControlStateNormal];
}
[btnPreviousNews setImage:[UIImage imageNamed:#"arrow1_prev.png"] forState:UIControlStateNormal];
count=count +1;
_lblNewsCount.text=[NSString stringWithFormat:#"%d/%d",count+1,[_arrUrlLinks count]];
NSLog(#"next %d",count);
[self performSelectorInBackground:#selector(DownLoadData:) withObject:[NSString stringWithFormat:#"%d",count]];
}
else{
btnNextNews.userInteractionEnabled=FALSE;
}
}
-(IBAction)btnPreviousClick
{
btnNextNews.userInteractionEnabled=TRUE;
if(count==0)
{
btnPreviousNews.userInteractionEnabled=FALSE;
}
else{
if(count==1)
{
[btnPreviousNews setImage:[UIImage imageNamed:#"arrow2_prev.png"] forState:UIControlStateNormal];
btnPreviousNews.userInteractionEnabled=FALSE;
}
[btnNextNews setImage:[UIImage imageNamed:#"arrow1_next.png"] forState:UIControlStateNormal];
count=count-1;
_lblNewsCount.text=[NSString stringWithFormat:#"%d/%d",count+1,[_arrUrlLinks count]];
NSLog(#"previous %d",count);
[self performSelectorInBackground:#selector(DownLoadData:) withObject:[NSString stringWithFormat:#"%d",count]];
}
}
}
Have you tried as like below methods,
UIScrollView * _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 10.0, 320.0, 280.0)];
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.pagingEnabled = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollsToTop = NO;
_scrollView.delegate = self;
[self addSubview:_scrollView];
float width = 0.0;
for (int i = 0; i < pageCount; i++)
{
UIView * yourView = [[UIView alloc] initWithFrame:CGRectMake((i * 320.0) + 20.0, 0.0, 280.0, 280.0);
[_scrollView addSubview:yourView];
width = yourView.frame.size.width + yourView.frame.origin.x + 20.0;
}
[_scrollView setContentSize:CGSizeMake(width, _scrollView.frame.size.height)];
Look at UIScrollView. To be honest this question makes it look like you've done very little research into the problem though. Can you tell us a bit more about what you currently have and what you've done so far?
UIScrollView Scroll depends on the ContentSize. So you have to set the ContentSize.
For Horizinatal Scrolling
[scroll setContentSize:CGSizeMake(1500, scroll.frame.size.height)];

AVErrorMediaServicesWereReset in AVCaptureSessionRuntimeErrorNotification

I have a problem with AVCaptureSession startRunning. It's problem only on iphone 5 with IOS 7. My app should record video and show all on AVCaptureVideoPreviewLayer, but if I test on iphone 5, first time call error = AVErrorMediaServicesWereReset.
This is my code, where I create capturemanager and startRunning:
-(void)startVideoTranslation{
CGRect r = videoBackView.bounds;
videoPreviewView = [[UIView alloc] initWithFrame:r];
[videoBackView addSubview:videoPreviewView];
if (currentGameType == MPGameTypeCrocodile){
if (captureManager == nil) {
captureManager = [[AVCamCaptureManager alloc] init];
[captureManager setDelegate:self];
if ([captureManager setupSession]) {
//Create video preview layer and add it to the UI
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[captureManager session]];
CALayer *viewLayer = [videoPreviewView layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [videoPreviewView bounds];
bounds.origin.y = bounds.origin.y+1;
[newCaptureVideoPreviewLayer setFrame:bounds];
if ([newCaptureVideoPreviewLayer.connection isVideoOrientationSupported]) {
[newCaptureVideoPreviewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
}
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
captureVideoPreviewLayer = newCaptureVideoPreviewLayer;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(isErrorSession:) name:AVCaptureSessionRuntimeErrorNotification object:nil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
[[captureManager session] startRunning];
});
}
}
}
}
And this selector I call here:
-(void)showPrepareView{
[self playSound:#"start"];
BGView.frame = videoBackView.bounds;
[prepareView addSubview:videoBackView];
[self startVideoTranslation];
[videoBackView addSubview:BGView];
In this code I use AVAudioPlayer in [self playSound:],
on videobackView i add my PreviewLayer.
Does anyone know the reason for this problem?
Now,I solve this problem so, I move in -(id)initWithFrame:
captureManager = [[AVCamCaptureManager alloc] init];
[captureManager setDelegate:self]
[captureManager setupSession];
[[captureManager session] startRunning];
But I don't understand what is it.

iPhone View Size Not Correct After Rotation

I am creating an iOS app that needs to run on all device. When creating a slideshow I did not want to have an image for each device. I creating a method to generate the images. It takes a background image, main sink image, and 2 UILabels and scales accordingly. For portrait orientation on all the devices it works perfectly. On the iPad I also need landscape. When I rotate it something goes wrong because it just stretches the images. I am not sure what is happening to my view bounds.
Sorry my code is so long.
-(void)viewDidLoad{
_screenSize = self.view.bounds.size;
_slideShowImageArray = [[NSMutableArray alloc] init];
_slideShow = [[NSMutableArray alloc] init];
for (int i = 1; i<=8; i++) {
[_slideShow addObject:[self slideNumber:[NSNumber numberWithInt:i]]];
}
[self generateImages];
_SlideImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, _screenSize.width, _screenSize.height)];
[[self view]addSubview:_SlideImageView];
[self setSlideNumber:[NSNumber numberWithInt:1]];
[self begin];
}
-(void)begin{
if ([_SlideNumber intValue] <=8) {
UIImage * toImage = [_slideShowImageArray objectAtIndex:[_SlideNumber intValue]-1];
[UIView transitionWithView:self.view
duration:1.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.SlideImageView.image = toImage;
} completion:^(BOOL finished) {
sleep(2);
[self begin];
}];
int SlideNumber = [_SlideNumber intValue];
int NewSlideNumber = SlideNumber+=1;
[self setSlideNumber:[NSNumber numberWithInt:NewSlideNumber]];
}
}
-(SlideShowObj*) slideNumber:(NSNumber*)number{
SlideShowObj * slideShowOBJ = [[SlideShowObj alloc] init];
UIImageView * counterTempImageView = [[UIImageView alloc]init];
NSString * imageName = [NSString stringWithFormat:#"bg%d.png",[number intValue]];
counterTempImageView.image = [UIImage imageNamed:imageName];
[slideShowOBJ setCounterTopIMG:counterTempImageView];
UIImageView * sinkTempImageView = [[UIImageView alloc]init];
imageName = [NSString stringWithFormat:#"sink%d.png",[number intValue]];
sinkTempImageView.image = [UIImage imageNamed:imageName];
[slideShowOBJ setSinkIMG:sinkTempImageView];
NSString * textAboveSink = #"";
NSString * textBelowSink = #"";
UIColor * textAboveSinkColor = [UIColor blackColor];
UIColor * textBelowSinkColor = [UIColor blackColor];
if ([number intValue]==1) {
textAboveSink = [NSString stringWithFormat:#"8 CAPTIVATING \nCOLORS"];
textBelowSink = [NSString stringWithFormat:#"Anthracite"];
textAboveSinkColor = [UIColor whiteColor];
textBelowSinkColor = [UIColor whiteColor];
}else if ([number intValue]==2) {
textAboveSink = [NSString stringWithFormat:#"TO ENHANCE \nANY DECOR"];
textBelowSink = [NSString stringWithFormat:#"Cinder"];
textAboveSinkColor = [UIColor whiteColor];
textBelowSinkColor = [UIColor whiteColor];
}else if ([number intValue]==3) {
textAboveSink = [NSString stringWithFormat:#"REAL TOUGH,\nFOR REAL LIFE"];
textBelowSink = [NSString stringWithFormat:#"Metallic Grey"];
textAboveSinkColor = [UIColor whiteColor];
textBelowSinkColor = [UIColor whiteColor];
}else if ([number intValue]==4) {
textAboveSink = [NSString stringWithFormat:#"HYGENIC+PLUS \nKEEPS IT CLEAN"];
textBelowSink = [NSString stringWithFormat:#"Café Brown"];
textAboveSinkColor = [UIColor blackColor];
textBelowSinkColor = [UIColor blackColor];
}else if ([number intValue]==5) {
textAboveSink = [NSString stringWithFormat:#"HEAT PROOF \nACID RESISTANT"];
textBelowSink = [NSString stringWithFormat:#"Truffle"];
textAboveSinkColor = [UIColor blackColor];
textBelowSinkColor = [UIColor blackColor];
}else if ([number intValue]==6) {
textAboveSink = [NSString stringWithFormat:#"SCRATCH RESISTANT \nSTAIN RESISTANT"];
textBelowSink = [NSString stringWithFormat:#"Biscotti"];
textAboveSinkColor = [UIColor whiteColor];
textBelowSinkColor = [UIColor whiteColor];
}else if ([number intValue]==7) {
textAboveSink = [NSString stringWithFormat:#"NON-FADING \nKEEPS IT CLEAN"];
textBelowSink = [NSString stringWithFormat:#"Biscuit"];
textAboveSinkColor = [UIColor whiteColor];
textBelowSinkColor = [UIColor whiteColor];
}else if ([number intValue]==8) {
textAboveSink = [NSString stringWithFormat:#"FOR THE LIFE \nOF THE SINK"];
textBelowSink = [NSString stringWithFormat:#"White"];
textAboveSinkColor = [UIColor whiteColor];
textBelowSinkColor = [UIColor whiteColor];
}
[slideShowOBJ setTopTextColor:textAboveSinkColor];
[slideShowOBJ setBottomTextColor:textBelowSinkColor];
[slideShowOBJ setTopText:textAboveSink];
[slideShowOBJ setBottomText:textBelowSink];
return slideShowOBJ;
}
-(void)generateImages{
for (int i = 1; i<=8; i++) {
UIImage * bgImage = [[(SlideShowObj*)[_slideShow objectAtIndex:i-1]counterTopIMG]image];
//find out the width and height ratio of your image.
double ratio = bgImage.size.width / bgImage.size.height;
//determine the calculate width according the height. here height is set as mainScreen.
double calculatedWidth = ratio * _screenSize.height;
UIImageView * bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, calculatedWidth, _screenSize.height)];
[[self view] addSubview:bgImageView];
bgImageView.image = [[(SlideShowObj*)[_slideShow objectAtIndex:i-1]counterTopIMG]image];
UIImage * image = [[(SlideShowObj*)[_slideShow objectAtIndex:i-1]sinkIMG]image];
//find out the width and height ratio of your image.
double ratio1 = image.size.width / image.size.height;
//determine the calculate width according the height. here height is set as mainScreen.
double calculatedWidth1 = ratio1 * (_screenSize.height)*.5;
double calculatedheight1 = ratio1 * _screenSize.width*.5;
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(_screenSize.width/2-calculatedWidth1/2, ((_screenSize.height)/2-calculatedheight1/2)*1.3, calculatedWidth1, calculatedheight1)];
[[self view] addSubview:imageView];
imageView.image = [[(SlideShowObj*)[_slideShow objectAtIndex:i-1]sinkIMG]image];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
UIFont *helvFont28 = [UIFont fontWithName:#"Helvetica" size:28.0];
UIFont *helvFont24 = [UIFont fontWithName:#"Helvetica" size:24.0];
UILabel * topText = [[UILabel alloc] initWithFrame:CGRectMake(0, (_screenSize.height)/2-(_screenSize.height)*.4, _screenSize.width, 100)];
[topText setNumberOfLines:2];
[topText setFont:helvFont28];
[topText setTextAlignment:NSTextAlignmentCenter];
[topText setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.2]];
[topText setTextColor:[(SlideShowObj*)[_slideShow objectAtIndex:i-1]topTextColor]];
[[self view]addSubview:topText];
[topText setText:[(SlideShowObj*)[_slideShow objectAtIndex:i-1]topText]];
UILabel * bottomText = [[UILabel alloc] initWithFrame:CGRectMake(0, (_screenSize.height)/2+(_screenSize.height)*.3, _screenSize.width, 40)];
[bottomText setFont:helvFont24];
[bottomText setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.2]];
[[self view]addSubview:bottomText];
[bottomText setText:[(SlideShowObj*)[_slideShow objectAtIndex:i-1]bottomText]];
[bottomText setTextAlignment:NSTextAlignmentCenter];
[bottomText setTextColor:[(SlideShowObj*)[_slideShow objectAtIndex:i-1]bottomTextColor]];
UIGraphicsBeginImageContext(_screenSize);
CGContextRef context = UIGraphicsGetCurrentContext();
[[[self view]layer] renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSLog(#"%f,%f",theImage.size.width, theImage.size.height);
[_slideShowImageArray addObject:theImage];
UIGraphicsEndImageContext();
[bottomText removeFromSuperview];
[topText removeFromSuperview];
[imageView removeFromSuperview];
[bgImageView removeFromSuperview];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[self reload];
}
-(void)reload{
[_SlideImageView setFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, _screenSize.width, _screenSize.height)];
[_slideShow removeAllObjects];
[_slideShow removeAllObjects];
for (int i = 1; i<=8; i++) {
[_slideShow addObject:[self slideNumber:[NSNumber numberWithInt:i]]];
}
[self generateImages];
[self setSlideNumber:[NSNumber numberWithInt:1]];
[self begin];
}
The frame of your view hasn't been correctly set in viewDidLoad method, yet. It would be more accurate to move frame-size related code to viewWillAppear: method. Dimensions of the frame will be correct in viewWillAppear: or viewDidAppear: methods. Then, you may want to keep a boolean variable in order to generate images at the first appearance only.

How do I use a for loop to display NSArray of UIImage's

Hey guys,
So.... lets say I have an NSArray of images
NSMutableArray *images = [NSMutableArray new];
[images addObject:[UIImage imageNamed:#"line1.png"]];
[images addObject:[UIImage imageNamed:#"line2.png"]];
[images addObject:[UIImage imageNamed:#"line3.png"]];
[images addObject:[UIImage imageNamed:#"line4.png"]];
Now I would like to load all these at once using a for loop but here is the catch.... I need to be able to set the images as hidden until the user unhides through interaction.
for (UIImage *image in images) {
UIImageView *line = [[UIImageView alloc] initWithImage:image];
line.hidden = YES;
[self.view addSubview:line];
}
But then how to I set the hidden BOOL to NO using another method?
As a secondary question, how would one release *line in the code above?
Thanks,
Darren
One option is to set up your images like:
int nextTag = 1;
for (UIImage *image in images) {
UIImageView *line = [[UIImageView alloc] initWithImage:image];
line.hidden = YES;
line.tag = nextTag;
[self.view addSubview:line];
[line release];
nextTag++;
}
...and then to unhide them you can do:
UIView* imageView = [self.view viewWithTag: lineNumber];
imageView.hidden = NO;
...assuming that your user-interaction handler is able to determine what line in the UI the user is interacting with.
As a secondary question, how would one release *line in the code above?
for (UIImage *image in images) {
UIImageView *line = [[UIImageView alloc] initWithImage:image];
line.hidden = YES;
[self.view addSubview:line]; // this retains the subview.
[line release]; // release line like this.
}
**
-(IBAction)btnReviewStar:(id)sender{
for (int i =([sender tag] ==30); i<36; i++) {
btnReviewStar.selected = NO;
btnReviewStar1.selected = NO;
btnReviewStar2.selected = NO;
btnReviewStar3.selected = NO;
btnReviewStar4.selected = NO;
if([sender tag] == 31) {
btnReviewStar.selected = YES;
break;
} else if([sender tag]==32) {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
break;
} else if([sender tag]==33) {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
btnReviewStar2.selected = YES;
break;
} else if([sender tag]==34) {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
btnReviewStar2.selected = YES;
btnReviewStar3.selected = YES;
break;
} else {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
btnReviewStar2.selected = YES;
btnReviewStar3.selected = YES;
btnReviewStar4.selected = YES;
break;
}
}
}
**

Resources