我正在尝试向页面添加一个新的子视图,以便除自身之外的所有内容都变灰。但是,我是从屏幕的子视图中调用它的。为了得到它,我必须执行以下操作:
[self.view.superview.superview.superview.superview addSubview:self.cardDialog.view];
Run Code Online (Sandbox Code Playgroud)
您可以猜测,这是非常糟糕的代码。如何找到合适的父级别并正确设置?
为了创建 xib 文件,我添加了一个新的 UIViewController 的可可触摸文件子类,并选中了“也创建 XIB 文件”。
我的 xib 文件中只有一个标签。
在我的视图控制器中:
import UIKit
class TestControllerViewController: UIViewController {
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
Run Code Online (Sandbox Code Playgroud)
除了我的 IBoutlet 之外别无他物(我至少检查了连接检查器 10 次)。
和我的自定义类:
import Foundation
import UIKit
class Card: UIView {
internal var number:Int?
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) …Run Code Online (Sandbox Code Playgroud) 当我从导航堆栈中弹出视图控制器时,弹出的导航控制器中的蓝色视图在离开屏幕时会出现延迟,并拖尾在视图控制器的其余部分后面,如视频所示:https : //vid.me /GbBG
这是什么原因,如何解决?
我CAShapeLayer在UIView. 它是一个半圆,上半部分,从左到右绘制。
以下是使用的代码,写在UIView子类中:
func drawSemicircle() {
// drawing an upper half of a circle -> 180 degree to 0 degree, clockwise
let startAngle = CGFloat(M_PI)
let endAngle = CGFloat(0.0)
let centerPoint = CGPointMake(CGRectGetWidth(frame)/2 , CGRectGetHeight(frame))
// path set here
let semirCircleLayer = CAShapeLayer()
let semirCirclePath = UIBezierPath(arcCenter:centerPoint, radius: CGRectGetWidth(frame)/2 - 20.0 , startAngle:startAngle, endAngle:endAngle, clockwise: true)
semirCircleLayer.path = semirCirclePath.CGPath
// layer customisation
semirCircleLayer.fillColor = UIColor.clearColor().CGColor
semirCircleLayer.strokeColor = UIColor(red: 237.0/255.0, green: 236.0/255.0, blue: 236.0/255.0, alpha: …Run Code Online (Sandbox Code Playgroud) 我正在构建一个实用程序,它在主视图和翻转视图之间共享数据.实际上,它并不是持有数据的翻转视图,它是自定义视图,它是加载时翻转视图的一个实例.我在这里解释了我之前的帖子中的细节,但我还没有解决方案.我已经重新开发了我的代码,希望这次我可以让自己清楚.
这里的一般概念是我在主视图中创建和存储数据,并使用FlipViewController中的预定义委托将其传递到翻转侧视图.然后在FlipViewController中,我将数据存储在我自己的委托中,并将其传递给实现我自己的委托方法的自定义视图.以下是代码的主要部分.
MainViewController.m(仅采用<FlipsideViewControllerDelegate>协议)
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.chart = data;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Run Code Online (Sandbox Code Playgroud)
FlipsideViewController.h
@protocol FlipsideViewControllerDelegate;
@protocol ChartDelegate;
@interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
id <ChartDelegate> delegate2;
DataModel *chart;
}
@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, assign) id <ChartDelegate> delegate2;
@property (nonatomic, retain) DataModel *chart;
- (IBAction)done:(id)sender;
@end
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
@protocol ChartDelegate …Run Code Online (Sandbox Code Playgroud) 我有一些代码可以实例化很多东西.此代码需要添加到视图中.因此,我需要能够使用view参数调用函数,然后将我的代码设置为方法体中的该视图.
这样做有什么选择?我读过你可以使用代表吗?但不确定如何.
这个问题看起来非常直接,但我有一个情况,我只需要一些帮助,如何以有效的方式做到这一点.比如说:我有三个视图视图1,视图2,视图3.
首先,我从基本视图推送View 1,然后从View 1推出View 2,然后从View 2推送View 3.现在View 3需要一个保存用户信息的对象.所以我在这里做的是将用户对象从基础1传递到视图1,并在加载所有视图时查看2和视图3,这里每个视图都将该对象存储为Ivar,即使视图1和2不使用.
我不认为从基地直接访问View 3来设置对象是好的,或者从View 3访问基础来获取值,任何想法的人如何处理这种情况.
作为初学者,我想澄清一下这个疑问.谢谢.
在我的项目中,我想在第一次启动应用程序时显示第一个运行视图.为此,我在我的mainViewCntroller.m中添加了一个UIView.为了忽略这个(重叠)视图,我在视图上放了一个名为acceptButton的按钮.我必须添加什么代码才能从堆栈中删除此视图?
我做错了什么?
这是我的代码:
- (void) firstRun {
if (((AppDelegate*)[UIApplication sharedApplication].delegate).firstRun)
{
CGFloat height = [[UIScreen mainScreen] bounds].size.height;
CGFloat width = [[UIScreen mainScreen] bounds].size.width;
NSLog(@"%f", height);
CGRect myFrame = CGRectMake(0, 0, width, height);
UIView *myView = [[UIView alloc] initWithFrame:myFrame];
myView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
myView.tag = 12345;
[self.view addSubview:myView];
// Create a ScrollView and a label
UIScrollView *discScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(20.0f, 0.0f, self.view.frame.size.width - 20, self.view.frame.size.height -70)];
discScroll.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UILabel *discLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
discLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth …Run Code Online (Sandbox Code Playgroud) 我有一个带有自定义原型单元格的表格视图,单元格上有3个不同的标签.如何访问这些标签?我需要改变他们的文本.我到处搜索过,在这种情况下找不到能帮助我的东西.我有以下代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"basicCell" forIndexPath:indexPath];
//change cell's 3 labels' text here
return cell;
}
Run Code Online (Sandbox Code Playgroud)
如何访问上面单元格的3个不同标签?
我需要你帮助使用uibezierpath或类似的方法在UIView上绘制这个边框.
我已经做了这个解决方案:在另一个中嵌入一个UIView,但我认为有更好的解决方案:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.theView.layer.cornerRadius = self.theView.bounds.size.width/2;
self.theView.layer.masksToBounds = YES;
UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(4, 4, CGRectGetWidth(self.theView.frame) - 8, CGRectGetHeight(self.theView.frame) - 8)];
borderView.backgroundColor = [UIColor grayColor];
borderView.layer.cornerRadius = self.theView.bounds.size.width/2;
borderView.layer.masksToBounds = YES;
self.theView.layer.borderWidth = 2;
self.theView.layer.borderColor = [UIColor redColor].CGColor;
self.theView.backgroundColor = [UIColor clearColor];
[self.theView addSubview:borderView];
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
uiview ×10
ios ×8
objective-c ×5
swift ×3
iphone ×2
border ×1
cashapelayer ×1
cocoa-touch ×1
delegates ×1
superview ×1
swift2 ×1
uilabel ×1
uitableview ×1
xib ×1