Hi all I'm implementing in my main ViewController some UIView custom class .. All are shown but only the KPHomeInfluenceUser is not visible .. Definitely it is a stupid question or lack of attention but you can explain why you do not see it ?? What am I doing is a wrong way to implement UIView Custom Class? If my method is wrong you can describe the correct method? I've seen many programmers implement classes this way.... Excuse me for stupid question
- (void)viewDidLoad {
[super viewDidLoad];
[self scrollView];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.calendar clearAllDataToHomeCalendarAndReloadData];
[self.calendar scrollHomeCalendarToCurrentDayAndMonth];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(UIScrollView *)scrollView {
if (!_scrollView) {
_scrollView = [[UIScrollView alloc] init];
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.scrollView];
[self.scrollView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;
[self.scrollView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = YES;
[self.scrollView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
[self.scrollView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor].active = YES;
[self calendar];
[self influenceUser];
[self homeBottom];
}
return _scrollView;
}
-(KPHomeCalendar *)calendar {
if (!_calendar) {
_calendar = [[KPHomeCalendar alloc] init];
_calendar.translatesAutoresizingMaskIntoConstraints = NO;
[self.scrollView addSubview:self.calendar];
[self.calendar.topAnchor constraintEqualToAnchor:self.baseUserPhoto.topAnchor constant:-5].active = YES;
[self.calendar.leftAnchor constraintEqualToAnchor:self.baseUserPhoto.rightAnchor constant:10].active = YES;
[self.calendar.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-10].active = YES;
[self.calendar.heightAnchor constraintEqualToConstant:85].active = YES;
}
return _calendar;
}
-(KPHomeInfluenceUser *)influenceUser {
KPHomeInfluenceUser *influence = [[KPHomeInfluenceUser alloc] init];
influence.translatesAutoresizingMaskIntoConstraints = NO;
[self.scrollView addSubview:influence];
[influence.topAnchor constraintEqualToAnchor:self.calendar.bottomAnchor constant:0].active = YES;
[influence.leftAnchor constraintEqualToAnchor:self.scrollView.leftAnchor constant:10].active = YES;
[influence.rightAnchor constraintEqualToAnchor:self.scrollView.rightAnchor constant:-10].active = YES;
[influence.heightAnchor constraintEqualToConstant:100].active = YES;
return influence;
}
Related
I would like to add a progress bar between navigation bar and UISearchBar. May I know how can I implement this? Please help. Thank you.
Here is my current code in Cell.m
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect barFrame = CGRectInset(self.searchBar.frame, 10.0f, 10.0f);
self.searchBar.frame = barFrame;
}
Here is my current code in ViewController.m
Did not reflect in this code after edited. _searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 24)];
- (void)viewDidLoad {
[super viewDidLoad];
_valueProgress = [[LDProgressView alloc] initWithFrame:CGRectMake(0,DCNaviH, ScreenW, 10.0f)];
_valueProgress.type = LDProgressSolid;
_valueProgress.color = ThemeRedColor;
_valueProgress.progress = 0.40;
_valueProgress.flat = #YES;
_valueProgress.showText = #NO;
[self.view addSubview:_valueProgress];
}
- (UISearchBar *)searchBar{
if (!_searchBar) {
_searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 24)];
[_searchBar setBackgroundImage:[UIImage imageNamed:#"ic_searchBar_bgImage"]];
}];
}
return _searchBar;
}
There are a few simple options for you depending on your apps UX. I think the best solution for you based on how you explained your issue would be to include the progress bar to your view and make sure it's above the other views while positioning it below the navigation bar.
_valueProgress = [[LDProgressView alloc] init];
_valueProgress.translatesAutoresizingMaskIntoConstraints = NO;
_valueProgress.type = LDProgressSolid;
_valueProgress.color = ThemeRedColor;
_valueProgress.progress = 0.40;
_valueProgress.flat = #YES;
_valueProgress.showText = #NO;
[self.view addSubview:_valueProgress];
[_valueProgress.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].isActive = YES;
[_valueProgress.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].isActive = YES;
[_valueProgress.heightAnchor constraintEqualToConstant:10.0f].isActive = YES;
if (#available(iOS 11.0, *)) {
[_valueProgress.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].isActive = YES;
} else {
[_valueProgress.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].isActive = YES;
}
And if the search bar has been added above the progress bar, you can always call [self.view bringSubviewToFront:_valueProgress] afterwards.
I have a DropAreaViewController in my app. Inside this controller I run the following code:
- (void)viewDidLoad {
[super viewDidLoad];
UIDropInteraction *interaction = [[UIDropInteraction alloc] initWithDelegate:self];
[self.view addInteraction:interaction];
}
- (BOOL)dropInteraction:(UIDropInteraction *)dropInteraction canHandleSession:(nonnull id<UIDropSession>)session {
NSLog(#"canHandleSession called");
return true;
}
- (UIDropProposal *)dropInteraction:(UIDropInteraction *)dropInteraction sessionDidUpdate:(nonnull id<UIDropSession>)session {
NSLog(#"sessionDidUpdate");
if (session.localDragSession != nil) {
NSLog(#"is localDragSession");
return [[UITableViewDropProposal alloc] initWithDropOperation:UIDropOperationMove intent:UITableViewDropIntentInsertAtDestinationIndexPath];
} else {
return [[UITableViewDropProposal alloc] initWithDropOperation:UIDropOperationCancel];
}
}
- (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session {
self.view.backgroundColor = [UIColor redColor];
}
Now, in another viewcontroller I add this controller:
DropAreaViewController *davc = [[DropAreaViewController alloc] init];
davc.view.frame = CGRectMake(0, 0, 100, 100);
[self.view addSubview:davc.view];
None of the drops are being registered though. I get not logs at all when I hover a drop on top of the square. Any ideas?
question one :
when a SearchController.searchBar as a tableview.tableHeaderView, and tableview have backgroundColor
why it has a strange color: image
question two :
How to use a SearchController.searchBar as a tableview.sectionHeader
when i try do it, my tableView will be so crazy image
code snippet :
- (UISearchController *)searchController{
if (!_searchController) {
_searchController = [[UISearchController alloc] initWithSearchResultsController: self.resultVC];
_searchController.searchResultsUpdater = self;
_searchController.delegate = self;
self.definesPresentationContext = YES;
// 是否添加半透明覆盖
_searchController.dimsBackgroundDuringPresentation = YES;
// 是否隐藏导航栏
_searchController.hidesNavigationBarDuringPresentation = YES;
// 可以通过此种方式修改searchBar的背景颜色
_searchController.searchBar.barTintColor = GL_NAVBAR_COLOR;
UIImageView *barImageView = [[[_searchController.searchBar.subviews firstObject] subviews] firstObject];
barImageView.layer.borderColor = GL_NAVBAR_COLOR.CGColor;
barImageView.layer.borderWidth = 1;
// 可以通过此种方式可以拿到搜索框,修改搜索框的样式
UITextField *searchField = [[[_searchController.searchBar.subviews firstObject] subviews] lastObject];
searchField.backgroundColor = [UIColor yellowColor];
searchField.placeholder = #"请输入搜索内容";
}
return _searchController;
}
- (void)configureUI{
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview: self.tableView];
self.tableView.backgroundColor = backgroundColor;
self.searchController.searchBar.frame = CGRectMake(0, 0, ScreenWidth, 44);
#if tableHeaderViewSearchBar
self.tableView.tableHeaderView = self.searchController.searchBar;
#endif
}
#if !tableHeaderViewSearchBar
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.searchController.searchBar;
}
#endif
You can place the UISearchBar of UISearchController in the navigation bar so that it remains fixed at the top.
So, just add below code at the end of configureUI method and remove last 2 lines of code inside the same method.
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.navigationItem.titleView = self.searchController.searchBar;
self.definesPresentationContext = YES;
I have a provisional idea:
- (void)viewDidLoad {
[super viewDidLoad];
[self.searchController.searchBar sizeToFit];
self.tableView.frame.origin.y = CGRectGetMaxY(self.searchController.searchBar.frame);
[self.view addSubview: self.searchController.searchBar];
}
To answer question one: you need to set tableView.backgroundView
UIView *tableBackgroundView = [[UIView alloc]initWithFrame:self.tableView.bounds];
tableBackgroundView.backgroundColor = GL_BACKGROUD_COLOR;
self.tableView.backgroundView = tableBackgroundView;
This is about a web browser.
I have a custom Class that handles the webpages.
SNBrowserView
SNBrowserViewPage
SNBrowserViewPages have two objects.
WKWebView
UIImageView // Snapshot of the WKWebView
A function either sustains or recovers a page for memory management.
(Testing) Whenever a page is selected I call a recovery function.
Selection:
- (void)browserView:(SNBrowserView *)browserView didSelectPage:(SNBrowserViewPage *)page
{
if (page.sustained) {
[page recoverAnimated:NO];
}
}
Sustain:
- (void)sustain
{
_sustained = YES;
if (_webView) {
_webView = nil;
[_webView removeFromSuperview];
}
_snapshotView = [[UIImageView alloc] init];
_snapshotView.frame = CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height);
_snapshotView.image = _snapshot;
[self addSubview:_snapshotView];
}
Recover:
- (void)recoverAnimated:(BOOL)animated
{
_sustained = NO;
_webView = [[WKWebView alloc] init];
_webView.frame = CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height);
_webView.navigationDelegate = self;
_webView.UIDelegate = self;
[self addSubview:_webView];
[self sendSubviewToBack:_webView];
[self loadURL:_initialURL]; // Start loading as early as possible.
if (animated) {
[UIView animateWithDuration:0.3
animations:^{
_snapshotView.alpha = 0.0;
}
completion:^(BOOL finished){
_snapshotView = nil;
[_snapshotView removeFromSuperview];
}];
}
else {
_snapshotView = nil;
[_snapshotView removeFromSuperview];
}
}
When I try to recover a page the snapshotView is not set to nil nor is it removed from the superview.
How is that even possible?
Even this won't work:
- (void)recoverAnimated:(BOOL)animated
{
_snapshotView = nil;
[_snapshotView removeFromSuperview];
}
The snapshotView is a subview, removeFromSuperview should always work, why is there MORE to it?
I suggest you try replace all of your
_view = nil;
[_view removeFromSuperview];
with
[_view removeFromSuperview];
_view = nil;
because what you are doing is setting the _view to nil and then removing nil from superview.
I am interested to write my custom view, so I created the following xib file:
This is the definition file:
- (void)_baseInit {
NSLog(#"Unseen View loaded");
[self addSubview:[self activityIndicator]];
[self activityIndicator].alpha = 1.0;
[self activityIndicator].frame = CGRectMake(round(([self imageView].frame.size.width - 25) / 2),
round(([self imageView].frame.size.height - 25) / 2), 25, 25);
[self activityIndicator].hidesWhenStopped = YES;
[self showIndicator];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(move:)];
[self imageView].userInteractionEnabled = YES;
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[[self imageView] addGestureRecognizer:panRecognizer];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self _baseInit];
}
return self;
}
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder])) {
[self _baseInit];
}
return self;
}
I tried to hook it up in my story board:
And I have my MainViewController call this during viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.unseenView = [[[NSBundle mainBundle] loadNibNamed:#"UnseenView" owner:self options:nil] objectAtIndex:0];
self.unseenView.delegate = self;
Unfortunately, nothing is showing up in my simulator literally nothing, not even the text labels.
However I am seeing the following log messages:
2013-02-20 17:37:58.929 Giordano.iPhone[66857:c07] Unseen View loaded
2013-02-20 17:37:58.934 Giordano.iPhone[66857:c07] Unseen View loaded
What am I doing wrong?
It looks like you are preparing your view correctly, but you are not adding it to the view hierarchy. in the viewDidLoad code you need to add this line:
[self.view addSubview:unseenView];