View is not replacing when going from portrait to landscape - iphone

I have a little subview that is not replacing when going from landscape to portrait. You can see it over here.
The code for the view is the following.
if ((self = [super initWithFrame:frame]))
{
self.autoresizesSubviews = YES;
self.userInteractionEnabled = YES;
self.contentMode = UIViewContentModeRedraw;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
self.backgroundColor = [UIColor colorWithRed:(80/255.0) green:(169/255.0) blue:(53/255.0) alpha:0.8f];
//CAGradientLayer *layer = (CAGradientLayer *)self.layer;
//UIColor *liteColor = [UIColor colorWithWhite:0.82f alpha:0.8f];
//UIColor *darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f];
//layer.colors = [NSArray arrayWithObjects:(id)liteColor.CGColor, (id)darkColor.CGColor, nil];
CGRect shadowRect = self.bounds; shadowRect.size.height = 4.0f; shadowRect.origin.y -= shadowRect.size.height;
ReaderPagebarShadow *shadowView = [[ReaderPagebarShadow alloc] initWithFrame:shadowRect];
[self addSubview:shadowView]; // Add the shadow to the view
CGFloat numberY = (0.0f - (PAGE_NUMBER_HEIGHT + PAGE_NUMBER_SPACE));
CGFloat numberX = ((self.bounds.size.width - PAGE_NUMBER_WIDTH) / 2.0f);
CGRect numberRect = CGRectMake(numberX+280, numberY-644, PAGE_NUMBER_WIDTH, PAGE_NUMBER_HEIGHT);
pageNumberView = [[UIView alloc] initWithFrame:numberRect]; // Page numbers view
pageNumberView.autoresizesSubviews = YES;
pageNumberView.userInteractionEnabled = NO;
pageNumberView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
pageNumberView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.4f];
pageNumberView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
pageNumberView.layer.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.6f].CGColor;
pageNumberView.layer.shadowPath = [UIBezierPath bezierPathWithRect:pageNumberView.bounds].CGPath;
pageNumberView.layer.shadowRadius = 2.0f; pageNumberView.layer.shadowOpacity = 1.0f;
CGRect textRect = CGRectInset(pageNumberView.bounds, 4.0f, 2.0f); // Inset the text a bit
pageNumberLabel = [[UILabel alloc] initWithFrame:textRect]; // Page numbers label
pageNumberLabel.autoresizesSubviews = NO;
pageNumberLabel.autoresizingMask = UIViewAutoresizingNone;
pageNumberLabel.textAlignment = UITextAlignmentCenter;
pageNumberLabel.backgroundColor = [UIColor clearColor];
pageNumberLabel.textColor = [UIColor whiteColor];
pageNumberLabel.font = [UIFont systemFontOfSize:16.0f];
pageNumberLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
pageNumberLabel.shadowColor = [UIColor blackColor];
pageNumberLabel.adjustsFontSizeToFitWidth = YES;
pageNumberLabel.minimumFontSize = 12.0f;
[pageNumberView addSubview:pageNumberLabel]; // Add label view
[self addSubview:pageNumberView]; // Add page numbers display view
trackControl = [[ReaderTrackControl alloc] initWithFrame:self.bounds]; // Track control view
[trackControl addTarget:self action:#selector(trackViewTouchDown:) forControlEvents:UIControlEventTouchDown];
[trackControl addTarget:self action:#selector(trackViewValueChanged:) forControlEvents:UIControlEventValueChanged];
[trackControl addTarget:self action:#selector(trackViewTouchUp:) forControlEvents:UIControlEventTouchUpOutside];
[trackControl addTarget:self action:#selector(trackViewTouchUp:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:trackControl]; // Add the track control and thumbs view
document = object; // Retain the document object for our use
[self updatePageNumberText:[document.pageNumber integerValue]];
miniThumbViews = [NSMutableDictionary new]; // Small thumbs
}

I think that you are using the autoresizingMask the wrong way.
Try changing the last line to this:
pageNumberView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Related

About IOS UIScrollView Sliding automatic will bounce back

My app's UIScrollView Sliding automatic will bounce back,what can i do?
I do not want!
my code below:
- (void)initScrollView {
// a page is the width of the scroll view
sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 96, 320, 300)];
sv.contentSize = CGSizeMake(sv.frame.size.width * 3, sv.frame.size.height* 2);
sv.pagingEnabled = YES;
sv.clipsToBounds = YES;
sv.showsHorizontalScrollIndicator = NO;
sv.showsVerticalScrollIndicator = YES;
sv.scrollsToTop = NO;
sv.directionalLockEnabled = YES;
sv.delegate = self;
[self.view addSubview:sv];
currentPage = 0;
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
pageControl.backgroundColor = [UIColor clearColor];
[self createAllEmptyPagesForScrollView];
}
- (void)createAllEmptyPagesForScrollView {
tapView1 = [[UIView alloc]init];
tapView1.backgroundColor = [UIColor clearColor];
tapView1.frame = CGRectMake(320*0, 0, 320, sv.frame.size.height);
tapView2 = [[UIView alloc]init];
tapView2.backgroundColor = [UIColor clearColor];
tapView2.frame = CGRectMake(320*1, 0, 320, sv.frame.size.height);
tapView3 = [[UIView alloc]init];
tapView3.backgroundColor = [UIColor clearColor];
tapView3.frame = CGRectMake(320*2, 0, 320, sv.frame.size.height);
[sv addSubview:tapView1];
[sv addSubview:tapView2];
[sv addSubview:tapView3];
}
i konw why I slide up automatically bounce back,my code have problem!Not bove code!thanks everyone!

a little uitextview position

i am writing this code to load a plist into 2 textview but i want them to adjust their height according to content size which i have done but i want the second uitextview to start from where the first one ends .. please help
for (int i = 0; i < arrresult.count; i++) {
NSArray *sorteddetail = [self.arrresult sortedArrayUsingFunction:sortint context:NULL];
DuaObject *duaobj2 = [[DuaObject alloc] initWithFilePath:[sorteddetail objectAtIndex:i]];
[duaobj2 loadFile];
CGRect frame;
frame.origin.x = self.scrollmain.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollmain.frame.size;
UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)];
UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)];
subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BG_text.png"]];
subview2.backgroundColor = [UIColor whiteColor];
[subview setFont:[UIFont boldSystemFontOfSize:14]];
[subview2 setFont:[UIFont boldSystemFontOfSize:14]];
subview.layer.cornerRadius = 10 ;
subview2.layer.cornerRadius = 10;
NSString *p = [duaobj2 dua_arabic];
NSString *b = [duaobj2 eng_trans];
subview.text = p;
subview2.text = b;
[self.scrollmain addSubview:subview];
[self.scrollmain addSubview:subview2];
subview.editable = NO;
subview2.editable = NO;
subview.textColor = [UIColor blackColor];
subview2.textColor = [UIColor blackColor];
subview.backgroundColor = [UIColor whiteColor];
subview2.backgroundColor = [UIColor whiteColor];
scrollmain.showsHorizontalScrollIndicator = NO;
CGRect frame1 = subview.frame;
CGRect frame2 = subview2.frame;
frame1.size.height = subview.contentSize.height;
frame2.size.height = subview2.contentSize.height;
subview.frame = frame1;
subview2.frame = frame2;
}
You can use two UIWebView for this. After fetching text data from plist ,redirect it on particular web view. and use [webView stringByEvaluatingJavaScriptFromString:#"document.body.offsetHeight;"] method to get height in pixel. According to height of pixel you can re-adjust web views frame.
Edit:
Look this one : How do I size a UITextView to its content?
It will help you.

LineHeight in EGOTextView

Im employing EGOTextView to do rich text editing. But the lineHeight of the EGOTextView appears a little smaller than in the UITextView, which are set the same font.
I have tried to set the kCTParagraphStyleSpecifierMinimumLineHeight and kCTParagraphStyleSpecifierMaximumLineHeight in the default attribute, but it is not a good solution as I need to insert image which has to modify the lineHeight. Any help will be appreciated:)
EGOTextView.m
- (void)viewDidLoad {
[super viewDidLoad];
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:#"UITextView", #"EGOTextView", nil]];
segment.segmentedControlStyle = UISegmentedControlStyleBar;
[segment addTarget:self action:#selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
[segment release];
if (_textView==nil) {
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textView.font = [UIFont systemFontOfSize:14];
[self.view addSubview:textView];
self.textView = textView;
[textView release];
}
if (_egoTextView==nil) {
EGOTextView *view = [[EGOTextView alloc] initWithFrame:self.view.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view.delegate = (id<EGOTextViewDelegate>)self;
[self.view addSubview:view];
self.egoTextView = view;
self.egoTextView.delegate = self;
[view release];
[self.egoTextView setFont:[UIFont systemFontOfSize:14]];
}
[segment setSelectedSegmentIndex:1];
}
You can set the kCTParagraphStyleSpecifierLineSpacing on the CTParagraphStyleSetting for the NSAttributedString to the number of points you would like to separate lines by. Alternatively, you could also specify a line height multiple using kCTParagraphStyleSpecifierLineHeightMultiple, for increasing line height by a factor.
Here's a quick example:
CGFloat lineSpacing = 0.f; // spacing, in points
CGFloat lineHeightMultiple = 0.f; // line height multiple
CTParagraphStyleSetting paragraphStyles[2] = {
{.spec = kCTParagraphStyleSpecifierLineSpacing, .valueSize = sizeof(CGFloat), .value = (const void *)&lineSpacing},
{.spec = kCTParagraphStyleSpecifierLineHeightMultiple, .valueSize = sizeof(CGFloat), .value = (const void *)&lineHeightMultiple}
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphStyles, 10);
[NSDictionary dictionaryWithObject:(__bridge id)paragraphStyle
forKey:(NSString *)kCTParagraphStyleAttributeName];
CFRelease(paragraphStyle);

iOS Overlay View - Masking UITableViewController with a view is partially masking UITableViewController

iPhone - 5.1(9B176)
I have been encountering inconsistent behaviour in overlaying a mask view on top of a UITableViewController as shown in picture below. Anyone encountered this behaviour, if yes, please suggest any solutions used?
Below is the code i have used to add mask view:
//Add the overlay view.
if(ovController == nil) {
NSString *cellIdentifier = #"overlayVC";
ovController = [[self storyboard] instantiateViewControllerWithIdentifier:cellIdentifier];
}
CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
CGRect frame = CGRectMake(0, yaxis, width, height);
ovController.view.frame = frame;
ovController.view.alpha = 0.85;
ovController.delegate = self;
UIView *aboveView = self.parentViewController.view;
[self.tableView insertSubview:ovController.view aboveSubview:aboveView];
I have also tried
`[self.tableView insertSubview:ovController.view aboveSubview:self.tableView]`
Hi use something like below code
-(void) showLoadingView {
//NSLog(#">>>>>>>>>>>>>>>>> loading view Landscape right ");
if (loadView == nil) {
loadView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadView.opaque = NO;
loadView.backgroundColor = [UIColor clearColor];
//loadView.alpha = 0.8;
viewBack = [[UIView alloc] initWithFrame:CGRectMake(95, 230, 130, 40)];
viewBack.backgroundColor = [UIColor blackColor];
viewBack.alpha = 0.7f;
viewBack.layer.masksToBounds = NO;
viewBack.layer.cornerRadius = 8;
spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(5.0, 5.0, 30.0, 30.0)];
[spinningWheel startAnimating];
// spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[viewBack addSubview:spinningWheel];
[spinningWheel release];
UILabel *lblLoading = [[UILabel alloc] initWithFrame:CGRectMake(23, 6, 110, 25)];
lblLoading.backgroundColor = [UIColor clearColor];
lblLoading.font = [UIFont fontWithName:#"Helvetica-Bold" size:16.0];
lblLoading.textAlignment = UITextAlignmentCenter;
lblLoading.textColor = [UIColor whiteColor];
lblLoading.text = #"Loading...";
[viewBack addSubview:lblLoading];
[loadView addSubview:viewBack];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
loadView.frame = iphoneFrame;
viewBack.frame = loadiPhone;
}
else
{
loadView.frame = ipadFrame;
viewBack.frame = loadiPad;
}
[self.window addSubview:loadView];
}
-(void) hideLoadingView {
[loadView removeFromSuperview];
}
declare this methods in you APPdelegate class so you can call it from any view in your code.
here i have set a view over the window not in view this surelu solve your problem!!!!

Thumbnail grid of images

How does one create a dynamic thumbnail grid?
How is a grid created with thumbnails of images like the photo app on iphone?
How are these spaces arranged dynamically? e.g. adding and removing thumbnails.
this is my simple grid view app
- (void)viewDidAppear:(BOOL)animated {
[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView];
temp = temp+1;
if (temp ==1){
NSLog(#"temp:%d",temp);
int n = 20; //Numbers of array;
NSArray *t = [[NSArray alloc] initWithObjects:#"calpie.gif",#"chrysler_electric.png",#"chrysler_fiat_cap.gif",#"cleanup.gif",#"ecylindri.gif",#"elect08.png",#"globe.gif",#"heat.gif",#"insur.gif"
,#"jobs.gif",#"office.gif",#"opec1.gif",#"orng_cap.gif",#"poll.gif",#"pollen.gif",#"purbar.gif",#"robinson.gif",#"robslink_cap.gif",#"scot_cap.gif",#"shoes.gif",nil];
myScrollView.contentSize = CGSizeMake(320, 460+n*2);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 1;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
NSString *mxiURL = #"http://meta-x.com/biflash/images/";
int i =0,i1=0;
while(i<n){
int yy = 4 +i1*79;
for(int j=0; j<4;j++){
if (i>=n) break;
CGRect rect;
rect = CGRectMake(4+79*j, yy, 75, 75);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
NSString *nn = [mxiURL stringByAppendingString:[t objectAtIndex:i]];
UIImage *buttonImageNormal=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: nn]]];
[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
button.tag =i;
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
//[self.view addSubview:button];
[myScrollView addSubview:button];
//[buttonImageNormal release];
[button release];
i++;
//
}
i1 = i1+1;
//i=i+4;
}
}
}
in AppDelegate
+ (Grid_ViewAppDelegate *)sharedAppDelegate
{
return (Grid_ViewAppDelegate *)[UIApplication sharedApplication].delegate;
}
- (void)showLoadingView
{
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor grayColor];
loadingView.alpha = 0.5;
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loadingView addSubview:spinningWheel];
[spinningWheel release];
CGRect label = CGRectMake(142.0f, 255.0f, 71.0f, 20.0f);
lblLoading = [[UILabel alloc] initWithFrame:label];
lblLoading.textColor = [UIColor whiteColor];
lblLoading.font = [UIFont boldSystemFontOfSize:14];
// UILabel
lblLoading.backgroundColor =[UIColor clearColor];
[lblLoading setText:#"Loading..."];
//[lblLoading setTextAlignment:UITextAlignmentCenter];
[loadingView addSubview:lblLoading];
}
[window addSubview:loadingView];
}
- (void)hideLoadingView
{
[loadingView removeFromSuperview];
}
definitely if u apply this logic. u get succeed